I need to rotate an object instantly by 180 degrees at the press of a button. The object is moving, I can rotate it on its Z axis using the joypad. Then, if I press a key I need my object to immediately invert its direction (ie: if it’s moving left, it flips and starts moving right).
I tried using Quaternion.Inverse, but it’s not working
Can you explain to me why not and point me to the right way to do it? (Sorry I’m kinda a newbie with Quaternions)
var craftSpeed:Vector3 = Vector3 (20,0,0);
var eulerAngleVelocity:Vector3=Vector3 (0,0,200);
var controlAxis:String ="HorizontalP1";
function Start () {
rigidbody.velocity = craftSpeed;
}
function FixedUpdate () {
// this aligns the velocity with the right vector, it makes the plane move towards its nose
rigidbody.velocity = Vector3.zero;
rigidbody.velocity = transform.right * craftSpeed.magnitude;
//this one just rotates my plane on input
var deltaRotation : Quaternion = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime* Input.GetAxis(controlAxis));
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
//and this one SHOULD make the plane invert direction on input
if (Input.GetKeyDown ("q"))
{
rigidbody.MoveRotation(Quaternion.Inverse(rigidbody.rotation));
}
}