- Home /
How do you move a character to another waypoint after landing on a specific waypoint
Hi, im making a simple snakes and ladders game in unity 2d for a school project using waypoints, but i cant find or figure out how to move the character up the ladders and down the snakes when landing on that specific waypoint.
Any help would be appreciated
Here is my Code for movement:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement : MonoBehaviour {
public Transform[] waypoints;
[SerializeField]
private float moveSpeed = 1f;
[HideInInspector]
public int waypointIndex = 0;
public bool moveAllowed = false;
private void Start () {
transform.position = waypoints[waypointIndex].transform.position;
}
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;
}
}
}
}
Answer by Ytsorf · May 13, 2021 at 07:39 PM
Hi there, you could try to put a Tag in the GameObjects you are using as a waypoint, in this way you can especify where to go when Xwaypoint is landed using CompareTags, hope it works
`
Your answer
Follow this Question
Related Questions
Easy WayPoint System - Character climbing at waypoint 0 Answers
How to play an animation with waypoints 1 Answer
Why isn't a Ai Waypoint Spawning??? 0 Answers
waypoint system help 1 Answer