- Home /
Rigidbody rotation around CenterOfMass
Hello.
I have a sphere with rigidbody attached to it in a cylindrel tunnel.
Basically I want to rotate this sphere around center point of Tunnel space.
This sphere has Gravity also. So that rotation looks realistic.
How can I achieve this?
I have tried rigidbody.AddTorque
But it rotates sphere around its center point.
CenTerOfMass of sphere is located at Blue point in image So that sphere can rotate at walls of tunnel.
The Image below gives clear Idea.
Thnx in advance.
An untested idea: Use Vector3.Cross() to calculate the cross product between the axis of the tunnel and a ray from the axis sphere to the axis. This will give you a side vector to the sphere you can use in a Rigidbody.AddForce().
hey. Thnx for your Idea.But what actually needs to be done I can't figure out from your answer.what does this 'ray from the axis sphere to the axis' means?
I've tried it But it gives some wiered behaviour to rigidbody. It throws the Ball out of the Tunnel.
Not sure what is going on without seeing a video. A couple of thoughts. You want to normalize the vector you get from the cross product so that the force you apply is uniform. You can use Vector3.Normalize() or just use Vector3.normalzied in the calculation. Next use Debug.DrawRay() to draw the Vector3 you get back from the cross product starting at the position of the ball. If you've done your calculations correctly, you should see a vector co$$anonymous$$g out of the size of the ball at a tangent to the surface of the tunnel. If this is not the case and you cannot figure it out, post the code back you are using. Last, you want to reduce the bounciness of the ball and the tunnel by changing the properties of the physic material you are using for both.
Are you trying to get the ball to roll around the inside of a pipe?
Also, you might want to go ahead and activate windows.
Answer by Berkays · Apr 12, 2013 at 11:56 AM
Maybe MouseOrbit script inside unity can give you an idea
Your answer
![](https://koobas.hobune.stream/wayback/20220613100123im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Constant Force doesn't work 0 Answers
Rigidbody rotation with PID controller and torque 0 Answers
How can I rotate around with a Rigidbody while respecting physics? 0 Answers
Rotating sphere with rigidbody attached 1 Answer
Object Reference Required to access non-static member 'UnityEngine.RigidBody.AddRelativeTorque' 1 Answer