Search Unity

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

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    71
    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. }