Object Selection Based on Variable

Yeah, hi, it’s me again.

So, I’m trying to make a segmented worm enemy for my 2D game, something like Eater Of Worlds from Terraria. For that I need to be able to tell each segment to follow the one in front. So I’ve given the object I’m using for this a variable and each instance of this object has a different value for this variable. Now I need to be able to select an object based on its internal variable in the parameters for the position in the “Apply force towards position” action. I don’t now how to do that. Someone help.

Here’s what I’ve tried so far.

In your first event, you want to set the value of WormLogic to 1, not add 1.

Ah, right, I forgot to mention I actually set WormLogic to 0 the step just above it, like this.

Presumably that’s functionally the same as what you suggested, but I tried it anyway and it is exactly as broken as before.

You say it’s not working. What’s is it doing? Is it moving any of the balls/worm components? And how have you allocated the value of Chain?

The first segment properly follows the player, but all the other ones just fly off to the right at a constant speed. As for the Chain allocation, its an object variable tied to the object BouncingBall and each instance on the scene has a different value for that variable, each one greater than the one before it. The starting segment has a value of zero.

Thanks for all your help by the way. I really appreciate it.

Have you tried the Animated Shadow Clones extension (not behavior) ?

Animate Shadow Clones [GDevelop wiki]

The second segment moves towards the position of the first. At the same time, the third segment moves towards the position of the second. And same again for segments 4 & 3, and so on. They all move at the same time.

You can do as @Keith_1357 suggests, though I’m not sure if the clones have hitboxes. If it’s just for visuals, then it should be suitable.

Otherwise, I’d suggest using physics behaviour (without gravity) and a physics joint between subsequent segments.

Thanks.
I’ll test the suggestion and see how it goes.

So I finally tried the animated shadow clone extension, and it works. Plus the shadow clones do have hitboxes. Thank you so much for your help.
The power of extensions in GDevelop is simply amazing. And I love the forum too. I’m happy to be here.

3 Likes