I have this POC where I’m testing bullet patterns, and I want to add a lifespan to bullets.
So here, I have a guy with various variables, one of them being bulLife. The plan is so that if I put any number in here (For example 1 for 1 second), then every bullet shot by the guy will only stay for a second, then it will be deleted.
The event above likely didn’t work because it has nothing in its condition except Trigger Once. That means, it only happens once, which is at the beginning of the scene. Instead of doing that, try putting that event as a sub-event of event where you spawn bullets.
Also if you want to gradually reduce the opacity of the bullet, giving it an effect of fading, you can try using the Opacity Tween.
The bullets are now disappearing when 1 second passes now, but now there’s another problem:
Notice the guy in the top left corner? His bulLife value is set to 0, meaning HIS bullets shouldn’t disappear. However, both guys seem to be sharing the same timer for some reason.
How can I make it so that the guys both have individual lifespan values?
In your first event, you’re setting the lifespan of bullet to the value of guy.Variable(bulLife).
The question is, which guy’s variable are you using? You’re not selecting the guy linked to each bullet. So GDevelop uses the first one in the list of all guy objects. You need to link them as a condition of the first event.
However, I’d question why you aren’t setting the bullet lifespan in the event that creates the bullet. I’m guessing at that point you know which guy it’s coming from, so there’s no fiddly little after events to worry about.
The guy in the middle has 2.5 as his bulLife value, so his bullets should last for 2.5 seconds. The guy in the topmost right corner has a 1 for the value, so bullets should last 1 second.
For some reason, the guy in the middle stole the corner guy’s 1 second value, and he’s using that for his own bullets. Additionally, the 2 guys at the top’s bullets don’t EVER disappear.
Why are you creating the link there? What are you doing? You need the link in the condition, as in all guys linked to bullet. How else will you filter out the correct guy object the bullet is linked to?
Also, think about it what you are doing. Think of the steps you are taking. Do they seem logical? As I explained, the in the first event you are not filtering the guy object to use.
Of course that won’t work; you are resetting the timer every single frame just before you check if it’s greater than the variable lifespan. Get rid of that first event completely, and just have the the second event and it’s subevent.
To confirm, the bullet lifespan check isn’t a subevent where the parent checks if state of guy is 5?
If not, can you provide screen snips of the updated events? Including where you check the bullet lifespan? There’s something that won’t be stacking up.
doesn’t act on anything for bullet types 0-4 because there is no linked bullet spinner. I wouldn’t have thought it would affect it, but you ever know.
Try making the delete bullet a separate event after the bullet spinner is unlinked and deleted (so the delete bullet event is a subevent of the lifespan timer check)
don’t appear to be part of the repeat for each guy block. You can confirm this by collapsing the repeat for each guy block. If you can still the the above events, then they’re not indented enough.