- Home /
Question by
MilkMike · Apr 18, 2021 at 03:53 PM ·
aiwaypoint system
AI waypoint not rotating in 2d worldspace
I was watching the Unity Learn tutorial on AI and they were teaching in 3d. I am trying to modify it to 2D but it doesnt work as I intended. It rotates in a way so the x rotation makes it invisible.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FollowWaypoint : MonoBehaviour {
public GameObject[] waypoints;
int currentWaypoint = 0;
public float speed = 10f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Vector2.Distance(this.transform.position, waypoints[currentWaypoint].transform.position) < 3)
{
currentWaypoint++;
}
if(currentWaypoint >= waypoints.Length)
{
currentWaypoint = 0;
}
this.transform.LookAt(waypoints[currentWaypoint].transform);
//this.transform.Translate(0, 0, speed * Time.deltaTime);
}
}
Any Idea why this is happening, please help me
Comment
Your answer
Follow this Question
Related Questions
Why isn't a Ai Waypoint Spawning??? 0 Answers
Make player follow a waypoint path but still be able to control player movement 1 Answer
Instantiated Enemy to Recognise Array of Waypoints 2 Answers
Waypoint Recognition 2 Answers
ENEMY HEALTH BAR 1 Answer