system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Yamz |
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
system
2
|
|
|
|
Reply From: |
kidscancode |
Raycast is not likely to help you much here. There are several possible approaches, with the simplest probably being this:
-
Put an Area2D on the enemy and connect its entered/exited signals.
-
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