Physics on and off

Hey guys, Here is what I would like to accomplish:
Have an object on screen that initially has rigid body turned off and when clicking to drag on letting go of the mouse turn the physics on. I am level 1 at Java scripting and using unity. Please mind the noobyness. :sweat_smile:

Hi, welcome to the forum!

The Rigidbody component has a setting called isKinematic that effectively turns physics on and off. If you set isKinematic to true:-

rigidbody.isKinematic = true;

…the physics will be disabled, but they will be reenabled if you set it to false again. When a rigidbody object is clicked with the mouse, it will report when the mouse button is released by calling the OnMouseUp function on the script. So, you would probably have something like:-

function OnMouseUp() {
   rigidbody.isKinematic = false;
}

However, you haven’t mentioned how the dragging is to take place or what will be happening in the game. (By the way, if you are using the DragRigidbody script to move the object, you don’t want to disable the physics during the dragging.)

Thank you very very much andeeee! I will give this a try tonight and watch the magic unfold. Cheers! :smile: :smile: :smile: :smile:

Heya andeeee, Worked perfectly thanks for you help. Hopefully I will become better at programming with time.