- Home /
Setting rigidbody's force to 0
I'm using a rigidbody.addforce for player movement, is this possible to set it to 0?
it's either
rb.AddForce(new Vector2(-rb.velocity.x , -rb.velocity.y), ForceMode2D.Impulse); //2d
or
rb.AddForce(new Vector3(-rb.velocity.x , -rb.velocity.y , -rb.velocity.z), ForceMode2D.Impulse); //3d
dependent on what your games dimensions are
rb just means rigidBody so if you don't use rb as a var
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-gameObject.GetComponent<Rigidbody2D>().velocity.x, -gameObject.GetComponent<Rigidbody2D>().velocity.y), ForceMode2D.Impulse);
this also works
Answer by Kiwasi · Aug 20, 2014 at 10:07 AM
Not sure exactly what you are asking.
To add no force to the player use RigidBody.AddForce(0)
To stop the player moving set RigidBody.velocity to zero
To eliminate all forces acting on a player then set RigidBody.velocity to its value on the last frame
I want it to immediately stop (to eli$$anonymous$$ate all forces acting on a player except gravity )
I dont know why, my player´s velocity is a constant zero but it keeps slowly falling down as if the gravity is affecting it.
Set Rigidbody.useGravity to false. This makes sure the velocity is not updated automatically with gravity.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Virtual Tour of a monument (scripting) 1 Answer
Cloud recognition in Vuforia 0 Answers
2d rotation and translation issue 1 Answer
Can a character can turn by using a click button in unity? 0 Answers