[SOLVED] Create multiple objects that circle around a centre object

I’m trying to create 3 objects “graveskull” that moves around in a circular pattern based on a central object “skullposition” and to spawn multiple copies of “skullposition”.

1st issue
I can only get one copy of “graveskull” to rotate at one time

2nd issue
When another copy of “skullposition” (green square) spawns the “graveskull” disappears from the 1st “skullposition” appears on the next.

Example screen of what I want to achieve


So, let me try to sum that up… you want for each skullposition, to repeat three times the following: create a graveskull and put it around skullposition at an angle of (spawnangle+=120)°. And then, for each graveskull, you want to put graveskull around skullpos at (angle+=5).
Is that it? Then do it :stuck_out_tongue:

I don’t know how to create multiple copies of “graveskull” objects and put them around “skullposition” at specific angles for example object 1 at 120° around centre object, object 2 at 240° and 3 at 360°?

also I don’t know how to have multiple copies of “skullposition” active at the same time without the “graveskull” objects resetting to the next “skullposition” created which also causes the rotation speed of “graveskull” to double?

seems like allot of events required overly complicated for what I want to achieve or I’m going about this the wrong way?

The action works but I don’t know how add more than one “graveskull” or the initial position in degrees around “skullposition”

All that I wrote in italics is really what you need to use inside GDevelop. You just need to modify the variables I wrote inside ( ) in a separate action, because you can’t change their value in the “put object around” action like I did.

Maybe you’re not aware of the Repeat event, though:

I think you need to take a step back and think about the high level design of what you are trying to accomplish. I will refer to your rotating skull thing as an “entity” below.
Think of it in phases:
1 - Spawn (this is done once for each entity)
2 - Animate / Move (this is done every frame for each entity)
3 - Clean up - (This is done whenever you want an entity to go away)

You could make this a function, or you can set a global variable, but the most important part is that this code only executes once when you create a new entity. You will likely just pass in a position. Or a skullpos object to center around. This is where you will call all of the create calls on the skulls and put them at the starting positions or set and instance variable on them with their starting angle. I reccommend also setting an instance variable called id on each skullpos, and an instance vriable on each skull object called “parent” which refers to the id of the skullpos it belongs to. Remeber this code should only run once per new object… maybe a big “TriggerOnce” block.

Animate / Move
This is done every frame, which is the default for all the code blocks. Use a Foreach skullpos object like Gruk explained. Move each skullpos if they are moving around. Then add an inner For each skull object where “skull.parent == skullpos.id”, and bump the angle of each of those skulls and reposition them around the skullpos.

Clean Up
When removing a skullpos from the scene, your can use a single condition like “skull.parent == skullpos.id” to select all the skulls associated with the skullpos and then call delete on “skull” and it will apply to all of them. Them you can delete the skullpos.

These are just design tips. It’s best to really think about these types of things before you start coding, but I often code first too, so no shame!

1 Like

Thanks for your reply… I got this to work as intended but using allot of events. I also had to make duplicates of graveskull as I don’t know how use instance variables on an object or parent and child objects.

The other issue is creating more than one instance of skullposition without having to duplicate all the events for each instance.


Any suggestion to do this with less events would be helpful or how to create more than one instance of skullposition without duplicating the same events.

Indeed, your solution is far from ideal.
Here’s the correct answer:

Looking back at my first message, I should have mentioned that you need 1. to link the objects if you have several skullpos, and 2. use object variables to avoid value conflicts between objects.


Thanks works great! I do have an issue still when I create another instance of skullposition the graveskulls do not repeat?


Ah, instances created during the game… I did not check that, indeed.
But I have formatted my computer in the meantime and I don’t feel like doing it over again. :sweat_smile:
Try moving the trigger once from inside the repeat, to inside its child.
Or nesting the repeat inside a lonely Trigger once, perhaps.
If that doesn’t work, share a json with this snippet, and I’ll see what’s wrong.

hi thanks for your reply. I messed around with the placement of trigger once but couldn’t solve the issue. link to the json file below


click (level) events then under the group named enemy click the grave event thanks for the help.

Not sure why it was conflicting, but I moved motionangle to the initialization loop, and it’s better now.

How did I know what to do? I opened the debugger and looked at the graveskull instances, and I noticed that the “motionangle” was the same for all three instances.

Resetting angle to 0 isn’t super necessary, but still a good thing to do, I guess.

1 Like

awesome you solved the issue! thanks for all your help I wouldn’t have worked it out myself or thought to check the debugger.

1 Like