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 f
Here is how to use MoveTowards
:
void Update()
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, PositionB, step);
}
LearnMore
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.