Hello,
I’m building a top-down game where my character is an helicopter.
The helicopter always looks to the mouse pointer, it Yaws to face the mouse.
The MoveRIghtAxis and MoveFowardAxis doesn’t care about the direction helicopter is facing in order to move the helicopter around, and helicopter flies in the X,Y plan (fixed Z).
I would like to Pitch and Roll the helicopter mesh to tilt in the exact direction the moveFowardAxis and moveRightAxis (control stick input axis) is facing, at a max of 30 degrees inclination, taking into the formula how far the stick is pushed.
For instance:
If my helicopter is rotated 90 degrees on Z (yaw=90), it would be looking to the “right” (mouse pointer would be there). Then, if I put the control stick all the way to foward (MoveFowardAxis = 1, MoveRightAxis = 0), I know I have to Pitch = 0 and Roll = -30 degrees (or MoveFowardAxis times MaxRoll times -1).
In the other hand, if it’s not rotated on Z (yaw = 0), it would be looking “foward” and if I put the stick all the way foward I have to Pitch = 30, but Roll = 0, and it tilts the way I want to.
In other words, I want my helicopter to tilt in the direction he’s going, not in the direction he’s facing. How would I do that? I would like to understand the Math behind this, if possible.
Since I have a foward vector and a right vector, how much pitch and roll do I add to them, based on MovementInputAxis, in order to tilt it in the right direction and with the right degree?
I’ve come this far until now:
//calculating Pitch
fPitch = MaxPitch * ((fMoveFowardAxis * fowardVector.X * -1)
+ (fMoveRightAxis * rightVector.X ));
//calculating Roll
fRoll = MaxRoll * ((fMoveRightAxis * fowardVector.X)
+ (fMoveFowardAxis * rightVector.X));
It’s pitching and rolling in the right direction, although I didn’t understand clearly why and I would like to. Also, when RightAxis and FowardAxis equals 1, it gives me a value greater than the MaxRoll or MaxPitch allowed. There are dirty ways to fix it (like restricting fRoll or fPitch to a max of MaxRoll and MaxPitch), but I would like to make it in a cleaner mathematic way.