How can I get my game object to rotate 180 degrees from its current position using code?

transform.rotation *= Quaternion.AngleAxis( 180, transform.up );

ok cheers, how can i get it to slerp to that angle:

transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);

When you wish to start the rotation, store the rotation transform.rotation * Quaternion.AngleAxis( 180, transform.up ); in a variable named “rotation” and put your script in update.

Quaternion q2 = Quaternion.Inverse(q1);

Inverse would also invert the other Axis.

B.t.w. I have another issue. I did exactly as it was explained here but for some reason it wont compare when i do:

```
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);
if(transform.rotation == targetRotation){
//rotation completed
}
```

It would work for all angles except a perfect 180. in some cases it says Y=1 and Y=-1 on the target rotation.

Now this is basicaly the same, except when you compare it, it isnt.

Also tried .Equals()

Meh. Fixed it. The magic word is:

Quaternion.Angle(transform.rotation,targetRotation)==0 (let Unity compare the angles)