Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity move in x seconds to pos

    StartCoroutine(moveToPosition(yourTransform, newPosition, time));

public IEnumerator moveToPosition(Transform transform, Vector3 position, float timeToMove)
    {
        var currentPos = transform.position;
        var t = 0f;
        while (t < 1)
        {
            t += Time.deltaTime / timeToMove;
            transform.position = Vector3.Lerp(currentPos, position, t);
            yield return null;
        }
    }
 
PREVIOUS NEXT
Tagged: #unity #move #seconds #pos
ADD COMMENT
Topic
Name
5+7 =