- Home /
How to remove all force from an object.
I have a pick up and hold script but sometimes the object falls through the floor (bonus points if you help me with that) and when I try to pick it up later (all my items gets picked up when I try to pick something up (again, bonus points if you help me with that)) the object spins around whilst I'm holding it. How do I remove all force on an object instantly through code?
Answer by Invertex · May 17, 2017 at 10:46 AM
Make sure to read the Documentation related to components you are having trouble with before asking a question :P
https://docs.unity3d.com/ScriptReference/Rigidbody.html
As you can see, there is an "isKinematic" option on your Rigidbody, this will disable physics on the object so that you can manually control the movement of a physics object.
And for the falling through floors, make sure your floors are square colliders with decent thickness. There is also a more expensive collisionDetection mode property for your rigibody that you can set, called ContinuousDynamic mode.
If your object is still spinning after setting it to Kinematic, the way you stop a rigidbody's current force is to simply set the rigidbody.velocity to Vector3.zero.
As for all objects being picked up, well we would have to see your code to know why that is happening!
I usually try to read the manual but I just couldn't find an anwser to this.
Answer by CrimOudin · May 17, 2017 at 01:38 PM
Increase the linear drag and angular drag on the rigidbody component. in code you can GetComponent().velocity = 0 and / or GetComponent().angularVelocity = 0.
If you move things using their transform you can experience weird collision effects try moving the RigidBody of your objects instead.
As for all your objects being picked up I would probably need to see code to help with that.
Your answer
Follow this Question
Related Questions
Add torque is not behaving same in opposite Y direction. Need help! 1 Answer
Flip over an object (smooth transition) 3 Answers
How To Accelerate/Decelerate Gradually With Torque GetAxis 1 Answer
How do I stop my enemy from falling over? 3 Answers
How to rotate an instance relative to the parent and give it force? 1 Answer