- Home /
How to make a character move to a specific waypoint?
Ok, so I am trying to make a Snakes And Ladders Game, And So Far I have implemented The ability for the characters to move after a dice being rolled (Using Waypoints). So every time the dice has 'landed' the characters move but I have not implemented the actual snakes and ladders. Is there a way that if the character lands on a specific way point (for example the snakes head) then to be transported to the way point on the snakes tail here is my code so far:
using UnityEngine;
public class FollowThePath : MonoBehaviour {
 public Transform[] waypoints;
 [SerializeField]
 private float moveSpeed = 1f;
 [HideInInspector]
 public int waypointIndex = 0;
 public bool moveAllowed = false;
 // Use this for initialization
 private void Start () {
     transform.position = waypoints[waypointIndex].transform.position;
 }
 
 // Update is called once per frame
 private void Update () {
     if (moveAllowed)
         Move();
 }
 private void Move()
 {
     if (waypointIndex <= waypoints.Length - 1)
     {
         transform.position = Vector2.MoveTowards(transform.position,
         waypoints[waypointIndex].transform.position,
         moveSpeed * Time.deltaTime);
         if (transform.position == waypoints[waypointIndex].transform.position)
         {
             waypointIndex += 1;
         }
     }
 }
}
Thanks in advanced!
Your answer
 
 
             Follow this Question
Related Questions
Why isn't a Ai Waypoint Spawning??? 0 Answers
Board-game pathfinding system (Similar to Mario Party style) 1 Answer
Waypoints C# unity 3d 1 Answer
Clones of Prefab not behaving as Prefab 1 Answer
Waypoint system on Click to Move (2D)? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                