- Home /
How To Freeze An Object Motion?
I'm trying to stop an object motion by applying force on it. For example, how could we freeze a free falling object in the air just by applying some force on it that would effectively set its velocity to zero?
Setting the velocity to zero manually would work fine if we decrease the FixedTimestep variable to a very low value, otherwise, the object would still fall slowly.
I've tried to apply a force equal to -velocity * mass, but the object still falls slowly.
Could anybody tell me how to do this just by applying some forces? (I mean without using Rigidbody's FreezePosition or IsKinematic variable)
Answer by robert 4 · Mar 03, 2011 at 09:49 AM
in components - physics add rigidbody check the box freeze rotation
rigidbody.isKinematic = true; // through scripting kinematic means no physics will apply at that time
that would work but it's not the answer to my question. But thanks anyway.
Answer by demize2010 · Jun 14, 2011 at 09:42 AM
Pretty easy one, just set the velocity of the rigid body to null.
var forceToAdd : Vector3 = Vector3(0,0,0);
rigidbody.velocity = forceToAdd;
There is a built in Vector.zero so you don't have to instantiate one. see http://docs.unity3d.com/Documentation/ScriptReference/Vector3-zero.html
This is definitely the best way to achieve this (well, as long as your incorporate musicm122's comment).
Answer by Speedy41 · Mar 05, 2011 at 06:23 AM
Looks like it can't be done. Since setting the velocity to zero doesn't freeze the object, I think that the gravitational force is applied by the physics engine after FixedUpdate() returns.
yeah I'm co$$anonymous$$g up blank with this too.
Would I would suggest is making an if clause or boolean before your addForce loops in FixedUpdate, that way you can stop force being added if certain conditions are met.
Your answer
Follow this Question
Related Questions
Force in Circular Motion 1 Answer
add force to object that has 2 different rigid bodies 0 Answers
Simple Rigidbody / force question 3 Answers
add torque at position 2 Answers
How to calculate force to apply to move object to a certain distance. 1 Answer