0 votes

Hello, sorry for this dumb question, but how can i make an enemy detect the player if it enters his area and then follow the player? Both player and enemy are kinematicbodys3d if it helps. Thanks for any answer.

Godot version 3.3.2
in Engine by (37 points)

1 Answer

+1 vote

By no means a dumb question infact wish there was someone to ask when I was trying to do it.

So it boils down to the type of game and the approach you want to use STATEMACHINE or EVENTMECHANICS

But I'll give a quick example here

Connect the body_entered, body_exited signals of the area node and enable/disable movement code

var follow_player = false

func _on_body_entered(body):
    if body == player_node:
        follow_player = true

func _on_body_exited(body):
    if body == player_node:
        follow_player = false

func _process(delta):
    if follow_player:
        #movement code here
by (5,842 points)

Thanks for the help, it is really hard for me to learn, do you know how could i print the collider name? just to test a few things

On the topic of learning, Just go at your own pace.

Something that works really well to get results from mammalia is positive reinforcement.
So every time you get that eureka moment or complete a task you've set out, reward yourself.

how could i print the collider name?

#for area nodes
func _on_body_entered(body):

#for raycast nodes
func foo():
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.