Rotation and Turn Giving Odd Angle
I have a helicopter player object - I want to make it so that when it moves forward the gameobject tilts forward - and back for backwards. The following is a snippet for how I have done this in the forward direction:
//If positive movement - forwards
float turn = 1 * 100 * Time.deltaTime;
Quaternion turnRotation = Quaternion.Euler(turn, 0f, 0f);
// Apply this rotation to the rigidbody's rotation.
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
This works and tilts the helicopter forwards for movement - however - when I turn the object it tilts it at an odd angle. I am wondering if it is to do with the object's centre mass or setting a pivot point for turn/rotation to be around? The following shows the Turn function:
private void Turn()
{
// Determine the number of degrees to be turned based on the input, speed and time between frames.
float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;
// Make this into a rotation in the y axis.
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
// Apply this rotation to the rigidbody's rotation.
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
}
And this is the issue at hand - normal pitch forward with movement: And now I add a turn: I guess it's kept the rotation in relation to X in the world's coords rather than X for the object? Weirdly when I print the objects angle it seems to still see a tilt forwards as being relative to the direction of the object.
Random bonus Q: If anyone can tell me an easy way to do addition/subtration with a 360 loop I'd love to know! Ie - forwards more than 360 is not >360 - it's now 5.
Your answer
Follow this Question
Related Questions
Struggling to get the rotation the player is moving in. 1 Answer
How to make player go forward when he is rotated? 0 Answers
Mathf.Clamp not clamping properly 0 Answers
I want to stop movement of character while i call animation like Kick Jump Punch etc.. Please help 1 Answer
Object's mesh does not move/rotate when object moves/rotates 0 Answers