Firing bullets in a stacked order?

I was just about to upload a version with ray cast but it occurred to me pick nearest object* form the arrow sprite’s x,y would work better.

Try online. click turret to delete. The target is draggable.

Project files:
doug13579/gdevelop-fire-once-from-each-turret (github.com)

3 Likes

wow that works perfectly! thank you for helping me out. :smile: I figured this would be simple but I was having allot of trouble. thanks for sharing the project.

1 Like

Yeh this is pretty awesome.

2 Likes

You’re welcome. I love the challenge. I tried other code and while it worked, it was getting too complicated. The code for shooting shouldn’t be larger than the entire game. Although, variables might have been safer if the objects moved a lot. What I like about this is it didn’t require IDs or any setup. It also automatically adjusts to additional or fewer turrets.

3 Likes

this is very handy. I think people could use this script for different things to happen in stacked order it could be turned into a stacked extension haha :thinking:

That’s what I was thinking, since I don’t have any need for turrets right now but this can be for a lot of things.

Actually though this is so cool I now want turrets in my project lol.

I don’t like the dependance on the nearest object. It works better for stationery objects. The pros are it doesn’t need any setup. I tried IDs. Renumbering the IDs after deleting one worked but it depended on which one was deleted. Whether it was before or after the current ID. It was just getting too complex. I considered ray cast and I also thought about adding the IDs to an array but I never tried that. I think it would be much easier in JavaScript.

2 Likes

I really like this idea - it’s thinking outside the box, is simple, is scalable and caters for all the scenarios of disappearing turrets. My only question is where is nearestObject? I’m assuming you’d place it above the top turret.

I placed an object above them. It was easier than using fixed numbers.

hello thanks again for the example I got around to implementing in my game and have run into a snag :sweat_smile: the problem is for example I have 3 turrets in a stack. like 1 enemy but with 3 parts. when I add another stack on the scene the fire rate of the first stack of turrets is messed up because it’s going through all the turrets on the scene? how can I have it so it only picks the 3 turrets in the stack and not all of turrets?

You would have to do something to differentiate the turrets like an index or group number stored as an object variable. Unless, the objects have different names. I would also use separate timers.

I made several changes to this but mostly just added checks for the object variable. I had to change the check for instances live on the screen to a “filtered” instance picked = false. I set up separate timers and time delay settings. I didn’t thoroughly test it but it seemed to work.

Project:
doug13579/gdevelop-fire-turrets-sequentially-with-multiple-groups (github.com)

1 Like

thank you for replying and posting the example I been mucking around with it and have managed to add additional stacks of turrets. I have to remember to assign different groupID number for each stack and also assign the same number to the turrets. I will implement in game and double check but I think it solved thanks.

1 Like

Earlier versions, I was going to use ray cast but I ended up using get nearest object to the arrow sprite. So, I added an arrow sprite for each group. What’s weird is if you move the arrow to the bottom, it will pick the turrets from the bottom. So, it will fire in reverse order. If you put the arrow in the middle, it alternates as objects above and below its position become the closest turret. No matter where the turrets or the arrow are, it seems to continue to work. It just changes the sequence. Although, they still only fire once per sequence. As long as the arrow sprite is closest to the first turret, it’ll fire from top to bottom.