Answers for "movetowards in unity 2d"

C#
9

unity movetowards

float speed;
Vector3 goalPosition;

void Update()
{
	transform.position = Vector3.MoveTowards(transform.position, goalPosition, speed * Time.deltaTime); //goes from the position of the gameObject to the goalPosition in a strait line with a speed of "speed"
  	//Also works with Vector2
}
Posted by: Guest on January-16-2021
0

unity movetowards 2d

transform.position = new Vector3(transform.position.x + movespeed, transform.position.y);
Posted by: Guest on March-16-2022

C# Answers by Framework

Browse Popular Code Answers by Language