How to make an Enemy, who can shoot me

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

Hello,
I am programming a fun game, for me and my friends. Its nothing special. Its a Platformer like Mario. In my secound world I wanted to add ranged enemies, but I can’t manage to do it. I searched everywhere in the internet, but didn’t find something. And the videos I found, I didn’t understand it. So can I may ask you for a tutorial how to do this? It would be really nice and would help me out. Hopefully someone answers me :slight_smile:

:bust_in_silhouette: Reply From: rinamon

More clear with the question, is it the shooting behaviour, the “shoot kan kill player” behaviour or what?

I think the best example would be shooter game tutorial , but apply the player logic for shooting enemies from the video to the enemies instead.

the basic flow that I can think of:

create a bullet scene (for instancing) contain area2D or RigidBody2D depends on your need, with logic of moving in 1 direction

enemy scene → create a timer signal → on_timeout , instance a bullet in front of the enemy sprite → if the bullet collision with player / player body entered the bullet, run damaging the player function

don’t forget to queue_free the bullet so it doesn’t make the game lag