I tried to make an aircraft move and rotate like normal, but something goes wrong when i try to rotate the airplane. The flaps, and all the moving parts on the aircraft: rudder, aileron, elevator do not move along.
my simplefied code (javascript) :
var rudder:Transform;
function Update() {
//THROTTLE
speed += Input.GetAxis("throttle") * acceleration;
//ROTATION
//Z
transform.Rotate(0,rotationRudder / 150,0);
//Y
transform.Rotate(rotationElevator / 150,0,0);
//X
transform.Rotate(0,0, -rotationAileron / 50);
//MOTION
transform.Translate(Vector3.forward * Time.deltaTime * speed / 100);
rudder.rotation.x += Input.GetAxis("horizontal");
}
but when I play the scene, and rotate my aircraft, this happens: (attachment 01)
and when i don’t rotate the aircraft it’s just normal (attachment 02)
In my script i have the flaps and elevator etc. called with a “:Transform”.
What is wrong with my script???
Hint: Transform.rotation is a quaternion, not a set of Euler angles.
I’m not sure exactly how to fix the problem, but based on my own experience, you really need to handle your rotations in Euler angles.
if you want to rotate flaps etc individually, try http://unity3d.com/support/documentation/ScriptReference/Transform-localEulerAngles.html
You don’t need to handle rotations using Euler angles - not in general, anyway. Euler angles and quaternions have different characteristics and behaviors, and each is useful in different situations.
But, maybe you’re just referring to the OP’s case (where Euler angles might indeed be the best way to go).
Well, thnx for all quick reactions, i will look at the quaternions (quite hard i thinks) THNX!!!
Well, you don’t need to use quaternions either
In short, use whichever representation is most appropriate for the task at hand.
I’m not sure exactly what you’re wanting to do, but for orienting flaps and so forth, manipulating the local Euler angles of the object doesn’t seem unreasonable, assuming that the object only rotates about a single axis. Just be sure you’re not trying to treat a quaternion as a set of Euler angles (as you appear to be doing currently).