How do I make my enemy ranged attack my player character at the same Y position as the player?

Hi everyone! It’s been a while since my latest topic, I’ve become quite better with Gdevelop, especially the use of variable. But anyway, how do I make my enemy ranged attack my player character unless they’re both have the Y position? I mean, enemy ranged attack unless the enemy is in tme same line as the player?

Just check if the
Use the one you want
enemy.Y() < player.Y()
enemy.Y() > player.Y()
enemy.Y() not equal player.Y()

Other approach could be adding an extra sprite to each enemy and use that sprites as line of sight, then check if player is in collision with line_of_sight_sprite do the enemy shoot logic.

Well, the first option didn’t do well. So I take the second option. The problem with the second is, I’m not so sure how to do that correctly and there are multiple ranged enemies along with a Timer to spawn the said enemy. So, can you explain me some more?

Yeah I’ve kinda hit a brick wall on that too. So if I have a timer spawning three enemies every ten seconds, and I want to spawn a “field of vision” sprite at the same time for each one of them, what’s the best way to go about that? Now that I’m thinking about it, maybe three different timers slightly offset would work, but that seems like overkill.

1 Like

Look here this is what I’m talking about

2 Likes

You’re right, I kinda forgot about this tutorial. Thanks!