Nik Myers Nik Myers - 2 years ago 89
Android Question

RigidBody gravityScale not working

I have a

, it attached to game object like this:

obj = GameObject.Find ("spider");
body = obj.AddComponent<Rigidbody2D> ();
body.angularVelocity = 180f;

So it's moving by gravity influence down from the screen, but i want it to stop at some point, so i've made a condition :

if (obj.transform.position.y < 0) {
Debug.Log("Stop point");
body.gravityScale = 0.0f;

I see in logs message "Stop Point" which notifies me that gravity should be stopped, but nothing is happening and object still going down, what am i doing wrong?

Answer Source

GravityScale indicate how many the gravity affect to your object. If your object is in movement, its have velocity, and gravity to 0 only tell that not add force to your gameobject, not stop this. Think that with gravity 0 is similar to an object in outspace, but with velocity its never stop. Use Addforce or Set velocity to stop your object.

body.velocity =;
body.angularVelocity = 0.0f;

//Ensure not move
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download