Multiple enemies made of multiple parts

Greetings,

For contexts sake; im making a sort of a knight duelling game. The player and enemies are supposed to be built with parts, and mostly tween-animated with code.
ive completed the player functionality. But alas, the enemies elude me. One knight on the screen works fine. But i havent been able to add more without them breaking.
Theyre built like this:
EnemyKnight <— spawned. Variable-tank etc
Legs <— created on Enemyknight
Torso <— created on Legs
Arms <— created on Torso
Head <— created on Torso
Etc.
Same as the player. One knight takes up a minimum of 10 parts.
I have been thinking there should be some other way than duplicating all of these objects. Its not that i mind. But future updates would be hell, so I’d rather not. And ive come to a point where i need to get this to work to move on. Final boss of this level. :slight_smile: I would appreciate any creative ideas.
Best regards.

Because you also need to give them all IDs
It is same principal as putting health bars for each enemies
It is not a problem to create separate healthbar for each enemy
It is problematic to tell game to which enemy move healthbar
And so you either need to link them to proper enemies or you give them ID variables and so you check if ID of healthbar is equal to ID of enemy and then you move one to another

So if you have knight it will work fine
But when you have two knights game do not know which knight you are referring
So you would need give 1st knight variable called FOR EXAMPLE ID
And set it to 1
Now you create 2nd knight and you give him ID variable and set it to 2
And now you create 2 sets of torso for example
Give one torso ID variable of 1 and other ID variable of 2
And now you use condition
ID variable of Knight is equal to ID variable of Torso

Action
Change Torso to Knight position X something Y something

And it will apply correctly to both knights

Same story with enemies

I am not 100% sure but i think you will also need to use repeat for each object event if normal event won’t work

1 Like

Thank you for replying!
It sounds to me that this solution is still creating several duplicates of bodypart-objects and linking them to an enemy-object.
Which would mean updating around 60 objects for 6 enemies. Im trying to link bodypart-instances to enemy-objects. So that i can, for example, add animations, or variables to only one bodypart instead of 6.
If this was what you meant then i didnt understand at all and im so sorry. My brain is a bit mushy after trying to get this to work for too long. I dont have a programmer-mind at all unfortunately.

Will you link or will you use variables it will be same thing
Difference will be how you did it

And it will work for all of them so that is exactly what it is meant to do

Never got stuck like this. I just cant grasp it. Maybe my brain needs some vacation time, but i will try a health bar tutorial. Maybe some things will become clearer.

Do not try to understand anything more than what i wrote
Look at it this way

You have two knights
Now you lets you have two helmets
Now you wanna one helmet go to one knight and other go to another knight
So you 1st use condition to take into account all knights instances that are not having a helmet
And put helmet on them
So if with that event you attach helmet to a knight then he can’t take another helmet so you can’t attach more than one helmet to a single knight
And since you created two helmets and other helmet is not attached to any knight and other knight do not have helmet
Then other helmet will go to other knight

And that is the principle on which it works

1 Like

Hey there!

Can you explain a bit better whats wrong? or what happens that you dont want to? …or just try to explain the whole picure a bit better in general :slight_smile:

Heres what i got so far:

  • Your making characters made of different moving parts
  • These parts are being moved with tweens (which might be the issue)
  • The player is fine, but something bad happens with the enemies if theres more than one.

Heres my questions…

  • Are you placing the enemies on the scene or spawning them after the scene launches?
  • Did you add a “For each object” on your enemy events?
  • If the enemies are being moved by tweens, if im not mistaken, each tween has to have a separate “ID” to not conflict with each other, are you giving each enemy their own tween “IDs”?

The “ID” thing can be kinda easy to make, all you have to do is:

  • Make a Global Number Variable, call it something like “TweenID”, starting at “0”
  • Now put the action "Change global number variable “TweenID” “add” “1"”, before the tween is used.
  • On the Tween “Identifier” put the variable “TweenID”.

I havent tried this, but it should work, just remember to not put the quotes or “”, on the tween identifier and just type TweenID for it to recognize the variable.

What all this is gonna do is, before a tween is played, the variable TweenID is gonna get a new number, for example, the first time its used, its gonna go from 0 to 1, then its gonna give the Tween Identifier that number, making it the “ID” for that specific tween.

This way every tween is gonna have its own “ID” and wont conflict with each other.
To “Reset” the “ID”, make a new Event with:
Condition:
Global number variable “TweenID” > (example) 1000
Action:
Change global number variable “TweenID” “Set to” “0”

Like i said, i havent tried it, but im fairly cretain it should work,

If you need more help with it, let us know, just try to give specific details so that we know whats going on :slight_smile:

1 Like

Yeah my confidence in using gdevelop kinda plummeted… :sweat_smile: I need to learn this, there will be bigger mysteries ahead. Im new to variables and this is just too abstract for now. Thank you for being so kind and patient.

What happens is that the bodyparts spawns on-top of each other and the instances created for each enemy doesnt seem unique for each enemy. Coz of the positioning-actions. Same thing happens when i ‘link objects’. The first spawned enemy 1 is fully functional, then i spawn enemy 2 and the bodyparts are created correctly on enemy 2 but then moves to enemy 1. Coz no ‘trigger once’. And ofc the thing im not understanding.
I tried doing something with variable ID’s as ZeroX4 suggested, but my brain didnt like it. :rofl: I dont even know how to approach it. I love problem solving and this feels like it should not be that difficult. I just dont understand the logic to write it.

The enemies are spawned with keypresses for now. T and R create 2 individual square lil enemy-objects. The legs are then created on them after. Then the torso on the legs, then the head and a hurtbox on the torso. I tried many combinations of ‘for each object’. I put a shake on the heads and as i hit one hurtbox both heads rattle.
The enemies does not have any tweens yet. I wanted to get them functional first. I’ll keep in mind what you said about tween-ids when i start with that. The player tweens works fine.

Take a screenshot of your events and post it here, that would be so much easier to help you out!

The reason all your enemies are doing the same thing isnt just because of where you put “Repeat for each object”, the issue is with the condition that triggers it.

For example, if you have something like:

Repeat for each enemy
Condition:
Player is in collision with Enemy
Trigger Once

Action:
Apply “Shake” on EnemyHead (or something like that)

What this does is that, only the enemy that is in collision with “Player” shakes his head.

If you do:

Repeat for each Enemy
Condition:
“R” key is pressed
Trigger once

Action:
Apply “Shake” on EnemyHead

What this one will do is, repeat “Shake” on every single enemy on the scene, because you didnt create a way to specify which enemy should be shaking his head.

Maybe you already know all this, but without knowing your events, i can only guess at the issue, so like i said, take a screenshot and post it here, youll instantly get the solution to your problem :slight_smile:

Also… and this is important…

No one is born knowing everything, dont feel down if you cant figure something out on your own.

I look stuff up all the time, then i study it, learn how it works and then find new ways of applying it to my projects, everyone does this.

…and at first, when i started working with variables on GDevelop, it seemed like something id never understand, but i started messing with it, reading about it, watched a couple videos and now everything makes perfect sense, so dont worry, im sure you will too :slight_smile:

1 Like

Forgot to tag you, read the post above :slight_smile:

Also… for the ID thing, check the video bellow, yes its for sounds, but its the exact same thing for the tweens, the difference is instead of adding the variable to the Sound Channel Identifier, you add the ID Variable to the Tween Identifier, everything else, is exactly the same.

1 Like

Sorry im so slow replying, i read your replies kinda instantly. Im trying to give my mind some vacation; which means staying away from gdevelop. :sweat_smile:


This is the shake.


Enemy 1.


Enemy 2.

This is how it looks.

I dont think i can do everything. Everytime i have a eureka moment im thinking “This program is genius.” :joy: I shouldnt do coding, but i want to make games and im stubborn.
Cant wait to get started with sound too. I love your videos. :heart:

Hey there! Sorry for the late reply, was kinda busy all day…

Glad your enjoying my videos!! Thanks for the support! :slight_smile:

Now as for your code… imma be honest bud, that is some convoluted code you got going, but im sure youv learned a lot by doing it :slight_smile: In time youll learn to keep things simpler.

Now as for your issue… the head shaking…
Your doing a “For every enemy”, then you checking distance to between hit boxes and finally… you tell it to shake “EnemyHealmets”… i mean… its all over the place.

If you want something specific to happen, you must be specific, and tell the code to do something specific.

For example, you “Linked” Enemy 1 and Enemy 2 to “BodyParts”, im guessing “EnemyHelmets” are in the “EnemyBodyParts” group.

So to tell it to shake the specific “EnemyHelmets”, try add the action “Take Linked Objects into account”, then say “Enemy1” and “EnemyHelmets”, that way your being more specific, that might be whats missing… ill try to have a better look at it when i have the time, but try it out untill then! :slight_smile:

I know its a mess. :slight_smile: Suspenders-and-belt frantics. Its how i problem-solve kinda. It usually get tidied up after it works.
Ive had some small breakthroughs tonight thanks to you. Not sure if i can build a system of it yet tho, as its less dynamic, and more specific. :joy: But its a start. I still think this could be done easier with variables somehow. But no ideas yet.
The distance between the objects-part is just a replacement for collisions.
Tomorrow the battle goes on. :sleeping: Sweet dreams.

Glad i could help a little :slight_smile:

Ok then, heres another tip to make things a bit more specific, but dynamic.

Start using “Object Variables” to trigger events, or to “filter” which Enemies you want to be affected.

For example:
Condition

  • Distance to player is less than 100 pixels
  • Object boolean variable “EnemyHit” is “False”

Action

  • Change object boolean variable “EnemyHit” to “True”
  • Shake
  • Wait (the duration of the shake) seconds
  • Change object boolean variable “EnemyHit” to “False”

Thats whats called “States”, its sorta like using “Trigger Once” but specific to the object your interacting with and waaay better.

Mess around with it to lean a bit mroe about variables.

You can also do the same thing with other kinds of variables, i just used the boolean because its easier to understand :slight_smile:

1 Like

This works, so far. The external event includes the enemy constructs, deaths and a test-tween so far. I will try your suggestions with variables next, as it will get more complex. :heart:

1 Like

Glad to hear your making progress!! <3

1 Like