How To Make A Enemy

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Xayln

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

:bust_in_silhouette: Reply From: ondesic

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.