Advanced Enemy Movement & Pathfinding // E47 // Make a 2D Action & Adventure RPG in Godot 4

Опубликовано: 20 Июнь 2026
на канале: Michael Games
5,019
245

In this tutorial we will build a pathfinder scene that we will use to improve the movement, pathfinding and feel of our goblin enemies chase state.

Topics Covered: RayCast2D, pathfinding, obstacle avoidance, dot product, Vector2, direction_to, working with arrays, array.find(), array.max()

Shout Outs:
The Trick I Used to Make Combat Fun! | Devlog by Game Endeavor:    • The Trick I Used to Make Combat Fun! | Devlog  
Advanced Enemy AI in Godot by Jacki Codes:    • Advance Enemy AI in Godot  


New Assets Needed:
N/A

Asset Download Page: https://michaelgames.itch.io/2d-actio...
GitHub Repo: https://github.com/michaelmalaska/aar...

Become a Patreon member to get exclusive access to Michael, and more:
https://patreon.com/user?u=26305011&u...

Join our discord community!
Discord:   / discord  

--------------------
Chapters
--------------------
0:00 Intro
0:48 Tutorial overview
4:23 The problem - enemy chase behavior is lame
9:06 Create "Pathfinder" scene
10:44 Add & configure RayCast2D nodes
15:00 Pathfinder script setup - script variables
19:25 Pathfinder script - _ready() function
20:25 Add Timer node to scene and script
22:59 Finish ready function - get all RayCast2D nodes
25:16 set_path function overview
31:28 Add "outcomes" array to code
32:23 Reset obstacle and outcome values
33:02 Check RayCast2Ds for collisions
35:37 get_next_i and get_prev_i functoins
37:08 Populate interests array
40:55 Add Pathfinder scene to goblin for testing
43:26 Calculate "outcomes" values
46:40 Integrate "pathfinder" scene as part of enemy chase state
51:02 Add direction variables to pathfinder script
52:02 Set best_path variable and test with chase state
56:37 Update Timer settings (reduce wait time)
57:29 Update Patfinder script to handle "no obstacles" condition
1:00:35 _process function, set move_dir using a lerp towards best_path
1:02:57 final touches on enemy chase state direction code
1:04:35 Test it out!
1:05:13 MOAR GOBLINS!
1:05:47 Decrease pathfinder raycast lengths
1:06:25 Outro / Patreon annoncement
1:08:04 Thank you to my supporters!
--------------------

Series Playlist:    • Make a 2D Action & Adventure RPG in Godot ...