- Home /
Rigidbody physics - equalizing force
Hi,
Basic idea: given a sphere on a plane to which a force is applied each frame. If user press a specific key, then I increase the drag of the object to not stop suddenly, and add a new force (equal or greater on opposite direction).
My question is how can i calculate the value of that force to make object to stop or even to go in reverse direction?
Thx a lot!
[Code snippet below]
void Update () {
rigidbody.AddRelativeForce(Vector3.right * 2);
rigidbody.drag = 1.0f;
if(Input.GetKeyDown(KeyCode.A))
{
rigidbody.drag = Mathf.Lerp(1.0f,6.0f,rigidbody.velocity.x * 0.5f);
rigidbody.AddRelativeForce(Vector3.left * 100);
}
}
Answer by meat5000 · Nov 07, 2013 at 04:19 PM
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-velocity.html
Note the difference between velocity and speed. Speed is Scalar (just a value) whereas Velocity has the value and a direction (speed in direction).
Simply read the value of the velocity and apply it in the opposite direction. Use ForceMode.VelocityChange if you choose.
You have set the value of Mass yourself so you can easily work out your Force but you probably won't need it.
Thx a lot, you'are right...i changed my approach based on you indication and everything is ok. $$anonymous$$any thank's!
Your answer
Follow this Question
Related Questions
Rigidody.velocity = Direction * speed; How to get direction? 1 Answer
Problems with Physics(Flipping strangely) 2 Answers
Direction of rotation and ApplyForce 1 Answer
Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers
Cannot move and jump with rigid body. 0 Answers