Hi all, I have a situation where two units fight each other using a timer to control attack frequency. (For example, each character has 20 health, and deals 10 damage every 3 seconds).
Currently, they would kill each other at the same time. However I recently added new attacks to stun the other player (basically pausing their timer for a few seconds). And what ended up happening is that one character would apply their stun effect before the other (the cool down would display 2.9 seconds)
How could I solve it so that they stun each other simultaneously?
#Simultaneous effects not simultaneous?
1 messages · Page 1 of 1 (latest)
there is no true simultaneity in computers (multicore etc can bend this rule, but it becomes wibbly wobbly unprovable ordering etc).
The best you can do imo is to have the stun effect be aware of which frame it started during, and come into effect the following frame, allowing other actions during this frame to flush. But this is complex, so there might be simpler approaches:
this might require a game manager that queues and executes updates to your game state
but it might not; you could also just have your attacks apply their effects with call_deferred() (which means all _process or _process_physics would run first, then the deferred queue drained; as long as both stun effects were applied via attacks in the same frame, both attacks would be in the deferred queue, and so both be applied)
however, if they're using timers or something, I don't think you'll be guaranteed same frame (you might! But it's not a rule), and so you might need to be more explicit about managing when the effects start or which effects are allowed to pierce it etc (like: the stun effect goes into effect at time X, but the second attack started before X, so the stun doesn't cancel it)