This code is supposed to rotate the gameobject in place, but as it rotates, it also slowly changes position. I don’t want the object to move as it rotates.
On a sidenote, if I set the rigidbody to kinematic this doesnt happen. I guess it has to do with the friction of the surface the object is on? Is there a way that I can rotate a gameobject with a rigidbody without it slowly moving?
Yes, I bet that’s it exactly. Remember, when you’re using the physics engine, you (mostly) don’t have fine control over the position, orientation, & movement of a Rigidody. You’ve ceded that control to the physics engine. It thinks the object should move a bit, so it moves a bit.
Well, of course you could freeze the position. Or you could possibly record what the position is at the start of the movement (in Start or whatever), and then reapply that every frame with MovePosition. It’s kinda being a jerk to the physics engine, but hey, it started it!
Adding on to @JoeStrout 's comment, setting a Rigidbody to Kinematic means you’ve taken control back from the physics engine for that object. An alternative way to keeping the object from misbehaving would be to zero out the velocities for the rigidbody when you know it should no longer move. Velocity is for position, angular is for rotation.
Maybe I’m wrong but I think that if you put the drag and angular drag to "Infinity, like this:
Your object should not be affected by the friction, but maybe you still want to keep the friction to apply to our object out of this situation so I’m not sure that this is the correct solution.
The one of JoeStrout, to record the position at the begining of the rotation seem good, but if you don’t need air friction, I find this one more simple