This is not really an answer since the problem is not entirely solved. But this is the code that works when my plane is not flying; I attached a simple rotate animation to the plane just to see if the controls will rotate locally and they work fine; However, when I put the code in my plane script (or use it as a separate controls script) the rotation is local to .. something else; meaning, they keep the pivot but they rotate - i think - relative to camera.
this is the code.
var smooth = 2.0;
var tiltAngle = 30.0;
var aileronR : GameObject;
var aileronL : GameObject;
var elevator : GameObject;
var rudder : GameObject;
function Update () {
var tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
var aileronRtarget = Quaternion.Euler (tiltAroundX, 0, 0);
var aileronLtarget = Quaternion.Euler (tiltAroundX, 0, 0);
var elevatorTarget = Quaternion.Euler (tiltAroundX, 0, 0);
aileronR.transform.localRotation = Quaternion.Slerp(transform.localRotation, aileronRtarget,
Time.deltaTime * smooth);;
aileronL.transform.localRotation = Quaternion.Slerp(transform.localRotation, aileronLtarget,
Time.deltaTime * smooth);;
elevator.transform.localRotation = Quaternion.Slerp(transform.localRotation, elevatorTarget,
Time.deltaTime * smooth);;
var tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
var rudderTarget = Quaternion.Euler ( 0, tiltAroundY, 0);
rudder.transform.localRotation = Quaternion.Slerp(transform.localRotation, rudderTarget,
Time.deltaTime * smooth);;
}
Another issue I have with this code is that I cannot use 2 axis; example - when I turn lean right, left aileron should be rotating up and the right aileron should be rotating downwards. I am just not sure where the problem is. Any help is appreciated.