Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Detect if an object has stopped moving.

Discussion in 'Editor & General Support' started by TouchSoft, Dec 9, 2008.

  1. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    I'm moving an object using AddForwardForce ...

    In the FixedUpdate function I would like to make a conditional checking if the object has stopped moving or not. How can this be done?
     
  2. careyagimon

    careyagimon

    Joined:
    Dec 20, 2007
    Posts:
    209
    one simple way:
    Code (csharp):
    1.  
    2. if(rigidbody.velocity.sqrMagnitude < .01  rigidbody.angularVelocity.sqrMagnitude < .01)//much faster than magnitude
    3.  
    those numbers might be higher/lower than you need.


    if you don't need to know instantly when it isn't moving, it might be better to check rigidbody.IsSleeping().
     
    LilGames likes this.
  3. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    thanks so much! that's exactly what was needed.
     
  4. Korpers

    Korpers

    Joined:
    Mar 15, 2013
    Posts:
    2
    Thanks - this worked for me too!