0 votes

I Want To Make A Enemy That Attacks The Player If The player goes inside a small area near enemy but if player gets out of the box it stops.
i have just started using godot so idk most of its function
and i have tried many things buts its not working! Pls help

asked Jul 31, 2019 in Projects by Xayln (12 points)

1 Answer

+1 vote

2 ways I can think of.
1. You could add something called a RayCast to the enemy, then every frame check if the player's position is within the RayCast's size, or
2. I would suggest using a CollisionShape2D node to the enemy. Under "shape" parameter use a circle and extend it to the radius you like.
Next find the Inspector panel. Next to it is the "Node" panel. Select it and attach a signal for the AreaEntered() of BodyEntered() signal (depending on if your player is an Area2D or a KinematicBody2D.
When your player enters the CollisionShape of the enemy, it will trigger the signal you created and your enemy can start firing at the player.

answered Jul 31, 2019 by ondesic (231 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.