0 votes

Hello, I wanted to make an AI that would attack you if you entered its area. Using the "Area" node as shown by this guy https://youtu.be/OSYehj6oa3U?t=1 but I would need this NPC to be able to attack as well, I can't code almost anything and I can't program my script to attack after entering to his zones.
I would be very happy if any of you could help me.
Here is my movement code, but with it the NPC chases you all over the map.

func _physics_process(delta):

var dir = (player.translation - translation).normalized()
dir.y = 0

if translation.distance_to(player.translation) > attackDist:
    move_and_slide(dir * moveSpeed, Vector3.UP)

PS: If full code is needed I will post it.

Thank you.

Godot version 3.5
in Engine by (12 points)

Please log in or register to answer this question.

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.