[SOLVED] Detect if an object no longer has any velocity on the y axis...

Hello,
I want to test if an object no longer has any activity on its y axis, so that I can trigger a game over functionality.

Basically, the object gets launched via a point effector. The object then bounces around, and when it no longer moves anymore on the y axis I want to Debug.Log(“GameOver”);

I can only test whether if the object is not moving anymore on the y axis, not the x. Because I have a surface effector on the ground object that constantly pushes the object forward. Hence, I only want to test for if the velocity on the y axis == 0;

Any ideas on how this can be achieved?

Please help!

if(rigidBody.velocity.y <= 0)
    DoStuff();
1 Like

Needs to be:

if(rigidBody.velocity.y == 0) {
    DoStuff();
}

Objects moving backwards have negative velocity.

1 Like

Thank you both for answering. I will try it out right now.

I have tried both code in the gameobject, but the console shows the message even when the gameobject isn’t stationary on the y axis.

Are you using RigidBody to move you objects? And not transform.

Are you using physics forces?

Try replacing rigidBody with ‘GetComponent()’ or 'GetComponent() if it has a 2D RigidBody.

I ended up setting up a system where it tests for zero velocity in the update method, triggers a IEnumerator timer, and checks is the transform on the y is equal or less than that of the ground. And that worked! Thank you both for helping me. I’ll mark this thread as solved.