#Vector3.Lerp doesnt reach position

1 messages · Page 1 of 1 (latest)

winged kiln
#

why when I make the step lower the piece doesn't reach the position?
when its 0.1 its fine. but its not smooth
when its 0.01 it still works but doesnt reach the second position
how can I fix this

public class AnimationScript : MonoBehaviour
{
    [SerializeField]
    private Transform Character;

    [SerializeField]
    private Transform Board;

    public float step;

    public int position;

    private void Update()
    {
        if (Input.GetKey(KeyCode.H)) {
            Transform PosTransform = FindPos(position);
            GoToPosition(PosTransform);
        }
    }

    public void GoToPosition(Transform Destination)
    {
        Character.position = Vector3.Lerp(Character.position, Destination.position, step);
    }

    protected Transform FindPos(int PosNum)
    {
        return Board.Find(PosNum.ToString());
    }
arctic cloak
winged kiln
#

i tried it its the same thing(but the animation curve is different) but I have to hold the button to reach the position

arctic cloak
# winged kiln thanks a lot! is it smooth like lerp thou?

That depends on how you use it.
In the end, both Vector3.Lerp and Vector3.MoveTowards are math formula that you put values into, and that give you back a value.

With Lerp, you give it two positions a and b, as well as a percentage t, and it will give you a value between a and b, based on t (so if t = 0.5, the returned value will be exactly in the middle between a and b).

With MoveTowards, you give it a current position current and a target position target, as well as a delta maxDistanceDelta. Then the method returns a value that moves current towards target by a maximum distance of maxDistanceDelta.

arctic cloak
winged kiln
#

thanks a lot it was really helpful!