Search Unity

Move an object towards a position at a fixed speed?

Discussion in 'Editor & General Support' started by MosquitoByte, Mar 10, 2020.

  1. MosquitoByte

    MosquitoByte

    Joined:
    Sep 17, 2018
    Posts:
    213
    I'm making an enemy for my game which patrols between a few points and i was wondering how i can make it move towards them at a constant speed? I was using Vector3.lerp but that seems to slow down once it nears the point.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
  3. MosquitoByte

    MosquitoByte

    Joined:
    Sep 17, 2018
    Posts:
    213
    thank you, this works great.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Vector3.lerp should work fine. To get a smooth lerp you must use the same start and end positions on each call and smoothly increase or decrease the float. I'm guessing you were using the object's current position as the starting position though, which would make it appear to slow down.