Search Unity

quick vector lerp question

Discussion in 'Scripting' started by Resilo, Jan 4, 2017.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    137
    solved delete thread please
     
    Last edited: Jan 4, 2017
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    If you ask something and solve it yourself it may be useful for others who google your question. So please rewrite your question (or don't do this next time if you're lazy) and answer it yourself
     
    eses likes this.
  3. MarshianMan

    MarshianMan

    Joined:
    Mar 27, 2015
    Posts:
    50
    For anyone else reading this, the original question was how to move a player forward using Vector3.Lerp, using a variable "dashstat" as the modifier.

    The original code:

    Code (CSharp):
    1. transform.position = Vector3.Lerp(transform.position, forward + new Vector3(0, 0, dashstat), 3.5f);
    Rather than declaring "forward + new Vector3" use the transform's position and forward axis to move the character.

    "dashstat" should be located in the time section of Vector3.Lerp, and multipled by Time.deltaTime if you are using it to lerp a certain amount over time.

    Code (CSharp):
    1. transform.position = Vector3.Lerp(transform.position, transform.position + transform.forward, Time.deltaTime * dashstat);
    However, if you want "dashstat" to move a certain distance with a certain speed, you could also multiply the transform.forward. This will increase the increments of which the player moves.

    Code (CSharp):
    1. transform.position = Vector3.Lerp(transform.position, transform.position + (transform.forward * dashstat), Time.deltaTime * speedVariable);
     
unityunity