Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How can I use LERP to move an object in its current movement direction?

Discussion in '2D' started by jleven22, May 20, 2019.

  1. jleven22


    Mar 26, 2019
    New to coding and Unity here, so forgive me if this is an easy answer.

    I'm trying to get my player to "dodge" based on its current movement direction over a period of time (the amount of frames to finish the dodge animation). For instance, if the player is moving right and presses the space bar, they move say 1 unit right.

    The game is top down, so I need to be able to dodge in all 8 directions. I suspect LERP is the right choice for this, but I could use a little clarity on how best to implement the math.

    Current movement script:

    Code (CSharp):
    1. private void Move()
    2. {
    3. transform.position = transform.position + movement * speed * Time.deltaTime;
    4. rb.velocity = new Vector3(movement.x, movement.y);
    5. }