Hi! I’ve been reluctant whether to post here or not since I initially thought it was a simple issue and could solve it without wasting someone’s time. However, I couldn’t find anyone who had the same or a similar problem and have been at it for a couple of days now (it’s for a jam).
So I’m making a top-down shooter consisting of only one room. There’s only 7 enemies, each a differentiated instance and their own separate object. The game looks like this:
(The “text” there is for debugging)
Right now, I have a “for each” event that picks the nearest object to the player whoose “awoken” variable is false, sets it to true, sets “look” to true, and plays a gun loading sound effect. This works something like an intro. The next event is that if “look” of enemies (a group containing all of the enemies) is true, then rotate towards player.X();player.Y().
The problem is that I want them to shoot, and I realized that, thanks to the room layout, there’s a big chance that they’ll shoot each other (in the back) if I just add simple shooting.
My first thought was to send a raycast from an enemy towards the player, test for enemies, and as an action (since the raycast hit something) maybe move the enemy away.
So I tried a couple of approaches, tried to implement AI chatbots to see if they could help me a bit, and lost days trying to get it to work. So I’m asking if anyone has any idea of how to make this behaviour come true. Thank you so much for reading!
Here are some code snippets:
(“John_Nato” is the name of the enemy I’ve been testing with. I think I’m going to have to repeat the event/s 7 times (for each enemy), but if you have any idea how to avoid that I’d be grateful if you’d share it below. I’m way past efficiency.)
(Last approach of tweaking the raycast angle, like a blind person with a stick on the street, if you will)