- Home /
Question by
talhahasan · Oct 12, 2015 at 05:43 PM ·
rotationmovementrotate
Rotation causing problem in Transform.forward
I have this script,
void Update () {
float pitch, yaw, roll;
pitch = Input.GetAxis ("Mouse Y");
yaw = Input.GetAxis ("Mouse X");
roll=Input.GetAxis ("Roll");
transform.Rotate (-pitch, yaw, -roll);
if (Input.GetKey (KeyCode.W))
Rigid.AddRelativeForce (transform.forward * 50);
else if (Input.GetKey (KeyCode.S))
Rigid.AddRelativeForce (-transform.forward * 50);
else if (Input.GetKey (KeyCode.D))
Rigid.AddRelativeForce (transform.right * 50);
else if (Input.GetKey (KeyCode.A))
Rigid.AddRelativeForce (-transform.right * 50);
else
Rigid.velocity = Vector3.zero;
if (Input.GetKey (KeyCode.Space)) {
transform.rotation = Quaternion.Euler (Vector3.zero);
Rigid.velocity=Vector3.zero;
Rigid.angularVelocity=Vector3.zero;
}
}
My "Roll" is defined as 'q' and 'e' keys. "Rigid" is rigidbody object.
I simply want to implement 6DoF on this cube, the pitch, yaw and roll works fine , but when it comes to movement it behaves in very unusual way after the object is rotated, I tried moving by using localPosition still no result. I also used relative torque for rotation but it resulted in worse, that is why rotation is controlled by transform.rotation not torque.
I suppose I am not handling gimbal lock or something? Or am I doing it completely wrong?
Comment