- Home /
How do I instantly change the direction of rotation of a gameobject?
I'm using a gameobject with a rigidbody2D attached to it. Naturally, when this object goes down a slope it spins in a certain direction, yes?
In my game, I'm trying to achieve momentum by using the physics from the rigidbody2d this way. However, I'm using these slopes not only on the ground, but in the roof aswell. The problem is that the momentum is halted when the gameobject goes from rolling on the ground to rolling in the roof, since it makes the gameobject spin in opposite directions.
My idea is to instantly reverse the spinning somewhere between the ground and the roof, so that momentum i kept, but I haven't had any luck programming it. I tried using: var target : Transform; transform.rotation = Quaternion.Inverse(target.rotation); But it doesn't change which way the the gameobject spins.
Answer by Glurth · Sep 23, 2015 at 01:46 PM
The transform element "rotation" is a poorly named variable IMHO, because it implies motion. It SHOULD be named transform."orientation", since it defines the current orientation/facing of the object. It does NOT define any rigid body or any time dependent components like speed or in this case, angular-speed.
Instead take a look at using Rigidbody2D.angularVelocity.