Problem with Rigidbody.rotation and AddTorque() being together
I want to tilt the Player (dron) if he is moving in any direction (along X and Z axis), just like in Space Schooter tutorial . But in the same time I want to rotate him with the joystick (around Y axis). I am using code like this:
void FixedUpdate()
{
float rotation = CrossPlatformInputManager.GetAxis("L_Horizontal");
float vertical_movement = CrossPlatformInputManager.GetAxis("L_Vertical");
Vector3 movement = new Vector3
(
CrossPlatformInputManager.GetAxis("R_Horizontal") * MovementForceMultiplier,
0.0f,
CrossPlatformInputManager.GetAxis("R_Vertical") * MovementForceMultiplier
);
if (DebugInfo) Debug.Log(player.velocity.magnitude);
Player.AddTorque(Vector3.up * rotation / TorqueDivisor);
Player.AddRelativeForce(0.0f, vertical_movement * VerticalForceMultiplier, 0.0f);
if (Player.velocity.magnitude < MaxSpeed)
Player.AddRelativeForce(movement);
Player.rotation = Quaternion.Euler(Player.velocity.z * TiltingMultiplier, Player.rotation.y, -Player.velocity.x * TiltingMultiplier);
}
What is happening? Player tilts, but rotation (AddTorque) changes slightly and only from 359 grades to 1 grade (2 grades angle) around Y axis.
I tried to use AddTorque (and AddRelativeTorque as well) for player tilting but it tilts him way too much and it is very hard to make boundaries on maximum rotation. I failed with that.
When I comment the "Player.rotation" changing, rotating player with AddTorque works very well.
I need tilting and rotating, because it has to simulate dron flight. Have you got any ideas, what can I do?