Skip to content Skip to sidebar Skip to footer

Moving An Object With Vector3.movetowards

I am working on a game app with Unity. I have an issue when it comes to move a GameObject . In my game, when the player swipes up with his device, the GameObject moves from a point

Solution 1:

Vector3.MoveTowards takes the current position, the target position, and the step, but it seems like your first argument here is origin of the move, rather than current position. Normally you'd do this something like this, in your Update():

transform.localPosition = Vector3.MoveTowards (transform.localPosition, PositionB, Time.deltaTime * speed);

with the current position as the first argument.

Solution 2:

Here is how to use MoveTowards:

voidUpdate()
{
    float step = speed * Time.deltaTime;
    transform.position = Vector3.MoveTowards(transform.position, PositionB, step);
}

LearnMore

Post a Comment for "Moving An Object With Vector3.movetowards"