Why does my rigidbody move it's transform while rotating?
The script on my Rigidbody allows the user to change its position and rotate it (through AddForce and AddTorque, respectively). However, when I rotate it, it moves ever so slightly (+/- 1 distance), which has a notable effect on the game. How do I make sure that the Rigidbody rotates around its center without changing its position at all? I thought about freezing the position, but that would bring the object's velocity to zero, correct?
Objects in Unity don't have a pivot property. Are you talking about the hierarchy (nested objects)?
Answer by Ady_M · Jul 15, 2017 at 03:41 PM
Check the center of mass of your Rigidbody.
Debug.Log (myRigidbody.centerOfMass)
If it's not (0, 0, 0) then the object's position will change when you use AddTorque.
Colliders of its children have an effect on the center of mass.
Example:
Parent (has Rigidbody)
-- Child (has collider). Local position is (0, 0, 5)
If you add torque to the parent in my example then the parent's position will change.
You can change the center of mass if you want:
myRigidbody.centerOfMass = new Vector3 (0, 0, 0); // or just Vector3.zero
Your answer
Follow this Question
Related Questions
AddForce in direction of different object? 1 Answer
How do i find player rotation and convert that into a force facing that direction. 0 Answers
Rigidbody changes position when I add torque. How do I stop this? 1 Answer
Mesh starts forcing from the wrong axis position 0 Answers
Torque rigidbody toward desired rotation on two axes ignoring Y axes? 0 Answers