2D PATHFINDING - Enemy AI in Unity

Brackeys · 882K views · 2019 · 23:13

Open on YouTube

Game programming & enginesIndie game developmentAlgorithms & data structurestutorial

Why Stack Overflow recommends it

Stack Overflow users link it as the A* tutorial they followed when asking about, or helping debug, Unity enemy AI that follows the player.

Recommended by 2 people across 2 different months, 2019 to 2024.

What it is

A Brackeys tutorial on building 2D enemy pathfinding in Unity using A* and Aron Granberg's A* Pathfinding Project. It first shows a no-code setup with AIPath and AIDestinationSetter, then a hand-written script using Seeker and Rigidbody2D.

What people said

Recommends Jack Mariani · 2019-07 · Stack Overflow · on “A variable is null eventhough i have already set it”

Is the first implementation of the tutorial working? The one with AIPath + AIDestinationSetter? If not it's just a matter of setting up the grid correctly (happeing at this point of the tutorial [this video] )

Recommends Altay Turan · 2024-08 · Stack Overflow · on “Problem in Unity's navigation system - getting stuck and time-consuming path calculations”

There is no specific cause actually. I searched for path finding systems and A* was the first result actually. A* Pathfinding [this video] This was the video that I used

Cites xyberr · 2019-07 · Stack Overflow · on “A variable is null eventhough i have already set it”

I was trying to make my enemies move using A* Pathfinding project (following Brackeys's tutorial, which can be found here [this video] ). In my Start() method, I use InvokeRepeating("GeneratePath", 0f, .5f); void GeneratePath() { if (seeker.IsDone()) seeker.StartPath(rb.position, Game.currentPlayer.GetComponent<Rigidbody2D>().position, OnPathComplete); } Then: void OnPathComplete(Path p) { if (!p.error) { path = p; currentWayPoint = 0; } } Notice that my path variable has been set. In my Update() method: public void MoveAI() { if (Game.currentPlayer == null || path == null) return; if (currentWayPoint >= path.vectorPath.Count) { reachEndOfPath = true; return; } else { reachEndOfPath = false; } Ve

Cites Byxbam · 2022-05 · Stack Overflow · on “EnemyAI script not moving the Enemy”

I am making my first foray into AI, specifically AI that will follow the player. I am using the A* Path finding project scripts, but used the Brackeys tutorial for the code [this video] Source in case needed. Here's the code using System.Collections; using System.Collections.Generic; using UnityEngine; using Pathfinding; public class EnemyAI : MonoBehaviour { public Transform Target; public float speed = 200f; public float NextWayPointDistance = 3f; Path path; int currentWaypoint = 0; bool ReachedEndOfpath = false; Seeker seeker; Rigidbody2D rb; public Transform EnemyGraphics; // Start is called before the first frame update void Start() { seeker = GetComponent<Seeker>(); rb = GetComponent<Rigidb