Enemy AI Movement/Attack

I’m using a sprite to activate a change in an enemies behavior upon collision with the player.

Unfortunately collision with one sprite activates for every mob in the scene. Is there a better way to do this so that each skeleton acts independently?

Or am I stuck creating new variables for every mob?

Any advice much appreciated

game

https://games.gdevelop-app.com/game-a5afaff5-8b62-4454-a0c9-16d849c13f37/index.html

Move the repat for skeleton inside the event when the player|circle occurs.

That way you first check if the player is in collision with the circle then apply foreach skeleton logic

Like this:
Condition:
For each skeleton
If player is in collision with Circle
take into account linked object
Skeleton animation = 1
Skeleton variable obj_var_is_attacking = 0
Note: Here I recommend to add an object variable to skeleton like obj_var_is_attacking by default 0 so in the collision you change to 1
Action:
obj_var_is_attacking = 1
Do other stuff

ok so i did it like this, but it didnt work.
will it work without adding the object variables?
everything works as intended except every collision circle triggers every skeleton to move/attack

Replace your walk and follow scene variables with object variables

1 Like

okay that works for the walking, im assuming that I will have to rework the attack to also use object variables.

or is this somehow salvageable?

okay im going to continue work under the assumption that I just didnt understand something fundamental about how things work and that I will have to switch to using object variables for these types of things.

I’m fairly certain I can work out most of the things I have going on but I did have one more question.

How would you go about deleting the left over circles after the enemies are gone?
Is there a way to delete the objects that are linked at the same time?

Thank you for the guidance with these issues, definitely wish I knew this earlier. Any resources you would recommend to get a better grasp on how all of the systems work?

There is an event type “For each Object”. You can access it by right-clicking an existing event and choosing “add other”, or by clicking the blue plus on the upper right.

I dont think that foreachobject is the answer to my problem.
I tested it out here anyways just to make sure, the attack still triggers for every instance of my skeleton guy this way.

You need a single for-each, and your events need to be subevents of that parent for-each event. After that point, you probably need to rework some of the events.

hmm, i also tried it that way making the foreach and then adding my other events under that parent event.
I think that object variables are going to make more sense and be easier to work with going forward.

Thanks for the help!
ill let you know if i get it working, seems like it might be a pretty common type of question.

If you know of any good guides on using gdev id appreciate that a lot as well!

Hey so I have been reworking these events and I’m pretty stuck again. I went with an object variable for the attack as well. I’m sure you can tell what i’m going for but its not really working and I cant seem to figure out why. Any tips? At this point I feel like it would take me less time to just make one of every enemy and not have to deal with it. But i really want to understand wtf is going on here.

As you can see any time I want to do something to each individual skeleton I have the repeat for each command. Is this whats causing everything to suck?

All of the sub events are organized pretty logically and I have pretty much triple checked everything but I cant seem to find whats going wrong.

If anyone can point me in the right direction here I would be eternally grateful!

current build- https://games.gdevelop-app.com/game-f6ca5003-d238-4ebe-a439-c04255da8063/index.html

Really feels like there is no other option but to create unique variables for each instance of the skeleton.

UPDATE

Basically back to where I started. Having issues with all the skeletons attacking whenever the player is in collision with any of the circles. ( Entropy from discord suggested use of takeintoaccount linked objects) I’ll try that next.

Also having some issues with movement animations that I haven’t isolated yet.
Here is the updated events page

Phew, that was a lot of back and forth with some pretty dumb mistakes on my part. Less is more definitely holds true here. My biggest problem was that I had no idea what I was doing. Second problem, too many “foreachobject” events and third was too many & conditions. Here is the updated events page, everything is pretty much working but who knows how long that will last.

The thing that is not working for me is that when two circles overlap only the collision for one works. Not sure if this is a limitation or if there is something I can do to fix it. If you have any ideas at all on how I could make it work please let me know.

Many thanks to all the people who helped me figure things out so far, really great community and glad I chose Gdev.

-Entropy
-Silver-Streak
-Slash
-UlisesFreitas

Okay wow, i think everything is finally working. Hopefully this helps others who are just starting out. A lot of the problems I ran into were pretty simple mistakes. In this last iteration the final problem was the order of the collision condition. We want to check if the collision circle is touching the player not the other way around. I still dont understand everything enough to explain exactly why things are(not) working but I’ll do my best to help anyone I can. Might be better to go with distance from object conditions for something like this. I pretty much just watched a bunch of youtube videos and tried to do what they did so I could get a better understanding of whats going on. If you are in the same boat just realize that what they are doing is probably not going to work for what you have in mind. That being said I think I learned way more by sticking to one problem and asking for help when I needed it. Dont give up you can do it! Anyways we can probably mark this thread as solved now.

Big thanks to
-Entropy
-SilverStreak
-Slash
-Greench
-And anyone else who helped along the way

1 Like