- Home /
Question by
videoanime · Feb 22, 2015 at 04:22 PM ·
movementvelocity
How to detect movement?
How could I detect movement or the absence of it? I tried with
if (Mathf.Floor(Mathf.Abs(rigidbody2D.velocity.y)) == 0) and with
if (rigidbody2D.velocity.y == 0)
and in both cases the if clause functioned when the real velocity was negative, I want tha some code happens when the gameobject is completely stopped.
Comment
Answer by MakeCodeNow · Feb 22, 2015 at 04:57 PM
Whenever comparing floats, you always want to use an epsilon. The easiest solution is like this:
if(Mathf.Abs(rigidbody2D.velocity.y) < 0.001)
Your answer
![](https://koobas.hobune.stream/wayback/20220613184007im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth movement using Rigidbody2d 3 Answers
Need help with my movement script.. :( 1 Answer
Ball moving in a tube 0 Answers
Slowing Down When Sliding Across Walls 2 Answers
Bullet not moving from script 3 Answers