0 votes

how to create a small ia for an enemy, which has to follow the player when he detects it

And seen in videos that you can use a raycast but if so what would be the code

asked Dec 6, 2019 in Projects by Yamz (73 points)

1 Answer

+1 vote

Raycast is not likely to help you much here. There are several possible approaches, with the simplest probably being this:

1) Put an Area2D on the enemy and connect its entered/exited signals.

2) When the player is inside this detect area, move towards it. To move towards something, you find the vector pointing to the target:

var dir = (target.position - position).normalized()

If you'd like to see a more detailed example of this, see here:

Godot Recipes: Chasing the player

answered Dec 7, 2019 by kidscancode (17,004 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.