- Home /
Waypoint system on Click to Move (2D)?
Hey all, I'm using a simple OnMouseDown function for movement (below) and I'm trying to get it to work with waypoints. I have gameobjects acting as waypoint nodes on my floor and I want to use them to do the usual navigating around obstacles.
I would like to store all the waypoints with a "FindGameObjectsWithTag" at the beginning and then navigate between them. The biggest issue, which might have to be added to my movement script, is that there is no coordinates dropped when the player moves towards their destination currently. If I need to add that, please let me know.
public float speed = 1.5f;
private Vector3 target;
void Start()
{
target = transform.position;
}
void Update()
{
if (Input.GetMouseButton(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
Having trouble getting Vector2.MoveTowards to work 1 Answer
How to move object repeatedly with Vector3.MoveTowards 1 Answer
2d click to move 2 Answers
How do I Force Particle System within an area and hide certain ones through arrays? 0 Answers
Loading Audio from Asset Bundles not working in Unity 5.2 2 Answers