Quaternions cancels transform.Rotate
I am working on a game where you play as a Drone, so I have a Quaternion.Euler controller your angle for hovering and use transform.Rotate to control the drone rotation. The problem I am having is that both lines of code work fine until you put them together, then Quaternion takes over the Rotate and you cant rotate the player. Here is my code:
Rigidbody rig;
float PlayerHeight;
float MoveX;
float MoveZ;
float RotY;
bool FlyUp;
public int thrust;
private void Start()
{
rig = GetComponent<Rigidbody>();
}
void Update () {
MoveX = Input.GetAxis("Horizontal");
MoveZ = Input.GetAxis("Vertical");
RotY = Input.GetAxisRaw("Y Rotation");
FlyUp = Input.GetButtonDown("Fly Up");
Vector3 movement = new Vector3(MoveX, 0.0f, MoveZ);
movement.Normalize();
rig.AddForce(movement * thrust);
transform.rotation = Quaternion.Euler(MoveZ * 20, 0.0f,-MoveX * 20);
transform.Rotate(0, RotY * 5, 0, Space.World);
}
I know that the problem is that the quaternion y is set to 0.0f, so when I try to rotate it only moves 5 on y instead of continuously adding 5, but I don't know an alternative to it without getting errors. Any help would be appreciated.
Your answer
Follow this Question
Related Questions
How do i rotate an object 90 or -90 degrees upon collision? 3 Answers
Quaternion.FromToRotation to calculate Rotation between two objects 1 Answer
Any simple ways of keeping track of simple rotation? 2 Answers
Does anyone know how to convert this rotation to lerp 1 Answer
More problems with arrow shooting 0 Answers