Search Unity

Move toward point(in one axis)...lerp..?

Discussion in 'Scripting' started by HenryD, Jun 14, 2010.

  1. HenryD

    HenryD

    Joined:
    May 6, 2010
    Posts:
    21
    Hi, i'm making my second game in Unity, it is a third person adventure about templar knights...

    Well, my problem is to make my player grab ledge, i did it, it is working...but i was using this command:

    Code (csharp):
    1. transform.position.y = collision.transform.position.y;
    with this, the player simply appear in the right point grabbing ledge...But i need the player move toward this point, i mean, smoothly.

    I use now:

    Code (csharp):
    1. if(grab==true) {
    2.     transform.position = Vector3.Lerp(transform.position, grabPos.transform.position,Time.deltaTime * 5);
    The variable grabPos was declared as gameObject when the collision happens.
    And now, the player moves toward the point in x, y, and z...but i don't want it. it unable player to move while on the ledge...

    Which command would i use to move like Lerp command, as one or two axis only..??

    Thank you so much!
    :D
    --
    Henrique Derosa
    Watch my first Unity game: http://www.youtube.com/watch?v=5jw2hVbIsk0
     
  2. dbp

    dbp

    Joined:
    Mar 3, 2010
    Posts:
    324
    you can use Mathf.Lerp instead of Vector3.Lerp if you want to lerp single values instead of vectors
     
  3. HenryD

    HenryD

    Joined:
    May 6, 2010
    Posts:
    21
    thank you dbp!!!

    Now i got a little problem, cause it is about global values...i mean...

    Code (csharp):
    1. transform.position.y = Mathf.Lerp(transform.position.y, grabPos.transform.position.y,
    2.         Time.deltaTime * 5);
    3.         transform.position.z = Mathf.Lerp(transform.position.z, grabPos.transform.position.z,
    4.         Time.deltaTime * 5);
    in the axis z i can't do this, because i want the z Local of the player, move to the z Local of the ledge...

    How would I do it? :p

    Thanks! =D

    --
    Henrique Derosa
    Watch my first Unity game: http://www.youtube.com/watch?v=5jw2hVbIsk0
     
  4. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    155
    I'm wondering the same thing. Anyone have an answer?