🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Flight controls | Wrong Yaw direction when overhead

Started by
3 comments, last by Fulcrum.013 5 years, 12 months ago

Hey guys,

I am having troubles with some basic flight controls.

When the plane is overhead the yaw is reversed so that left is right.

Do I need to multiply the yaw with the local up vector? 


var turnRateX = Input.Mouse.Position.X - 0.5f; // MousePosition is normalised [0 to 1]
var turnRateY = Input.Mouse.Position.Y - 0.5f;

var turnRate = IsBoosting ? maxTurnRateBoosting : maxTurnRate;

turnRateX *= turnRate / 60f * -1f;
turnRateY *= turnRate / 60f * -1f;

YawSpeed = turnRateX;
PitchSpeed = turnRateY;

Yaw += YawSpeed;
Pitch += PitchSpeed;

Entity.Transform.Rotation = Quaternion.RotationYawPitchRoll(Yaw, Pitch, 0);

How do I fix this?

Advertisement

Don't you want to be applying rotational inputs in the local coordinate space (i.e. Transform.LocalRotation)?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I am not using Unity at the moment.

1 hour ago, Twaxx said:

When the plane is overhead the yaw is reversed so that left is right.

Looks like you rotating it respectively to global axes basis. But it require to rotate respectively to local plane basis axes. To avoid a gimbal locks etc, you have to avoid to calculate rotation from global Euiler angles. Using of local Euler angles is ok.

Entity.Transform.Rotation = Quaternion.RotationYawPitchRoll(YawSpeed, PitchSpeed, 0) * Entity.Transform.Rotation;



 

#define if(a) if((a) && rand()%100)

This topic is closed to new replies.

Advertisement