Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Lerp Lanes

Discussion in 'Scripting' started by Eltu, May 10, 2014.

  1. Eltu

    Eltu

    Joined:
    Jan 15, 2014
    Posts:
    3
    Hello..
    I am trying to make a runner game with lanes...
    I have the movement on Z axis and Lerping on X axis
    but the lerp is not smooth....it gets stuck at half point on the X axis

    is it coz of the movement ?

    here is my code on the update function

    Code (csharp):
    1.         if(Input.GetKeyDown(KeyCode.Q))
    2.             transform.position = Vector3.Lerp(transform.position, new Vector3(-3.75f, transform.position.y, transform.position.z), 100 * Time.deltaTime);
    3.         if(Input.GetKeyDown(KeyCode.W))
    4.             transform.position = Vector3.Lerp(transform.position, new Vector3(-1.25f, transform.position.y, transform.position.z), 100 * Time.deltaTime);
    5.         if(Input.GetKeyDown(KeyCode.E))
    6.             transform.position = Vector3.Lerp(transform.position, new Vector3(1.25f, transform.position.y, transform.position.z), 100 * Time.deltaTime);
    7.         if(Input.GetKeyDown(KeyCode.R))
    8.             transform.position = Vector3.Lerp(transform.position, new Vector3(3.75f, transform.position.y, transform.position.z), 100 * Time.deltaTime);
     
  2. Gentleman Whale

    Gentleman Whale

    Joined:
    Apr 26, 2014
    Posts:
    6
  3. Eltu

    Eltu

    Joined:
    Jan 15, 2014
    Posts:
    3
    i just tried MoveTowards... and its still the same as lerp
     
  4. bara1247

    bara1247

    Joined:
    Oct 22, 2012
    Posts:
    40
    GetKeyDown doesn't loop , try GetKey
     
  5. Eltu

    Eltu

    Joined:
    Jan 15, 2014
    Posts:
    3
    yay, Thanks man this got it working like i wanted :D