- Home /
CONTROL RIGIDBODY MOVEMENT
I have a container with an exit opening in which there is ball. A rigidbody is attached to the ball. What I want to do is whenever i rotate the container, I want the ball to move towards the exit opening. Whenever I rotate the container to some degree the ball starts moving now if i want to stop the ball from moving I have to rotate the container in the opposite direction. Result is fine ball stops but it takes time because the inertia has to be cancelled by the new forces that are acting on the ball in the opposite direction. I was hoping is there anyway that whenever i rotate the container the ball starts moving and when i change the rotation of container the ball changes its direction immediately not after inertia/momentum of previous movement has been cancelled.
Answer by camdenlink7 · Jun 17, 2019 at 02:10 PM
I believe what you will have to do is add a force or change the velocity of the ball to get it to move toward the exit. It will be very difficult to get the ball to move to where you want it to with just physics and not actually moving the ball. I hope I understood your question correctly and hopefully this helps!
Thank you @camdenlink7 . I tweaked the values of rigidbody component and it worked for me. And you are right changing velocity is the best option.
Answer by kreaturian · Jun 17, 2019 at 08:30 AM
I'm assuming what you have in your code is
Rigidbody.AddForce(x float, y float, z float);
This only adds force. Not overrides it, which is why you have the initial momentum. Instead you should be using:
Rigidbody.velocity = new Vector3(x float, y float, z float);
This overrides whatever force you had before and replaces it with whatever forces you have here. Keep in mind that the velocity floats are a lot less than force, so instead of adding force as 500, change the velocity to say, 5.
U didnt undestood my question properly i think. I am not moving the ball. I am rotating the container. Ball is in the container. When container tilts, ball moves due to physics.