How do I…
Make same events apply to the same objects, but running on different instances?
Summary
I’m trying to make a “Smash Bros” like game, and to spare memory, events and lag, I came up with a multiplayer system using the same objects and a “ID” variable. However, there are some unexpected stuff happening, like damage being inflicted to the wrong object and the jump not working after jumping 2 times.
Also, I’m sorry for the long post, but I have no actual idea on how to explain this in a more summarized way
What is the expected result
I’m trying to make a “Smash Bros” like game, and to spare memory, events and lag, I came up with this system:
For instance, I have added 2 of the same player object into the scene, however, each one of them has a different variable named “ID”, which will identify which is player 1, which is 2, and so on (you can see a use of the variable in “Check for xxx input on player Player.Variable(id)”)
The expected result is, all of these actions should run separately on each player object, this way, if I create a 3rd player, I don’t need to copy paste all of the events for the player
What is the actual result
There’s 2 things that are making this system “not functional”:
-
The jump system; These events define how I programmed it:
When the player jumps and the variable “jumps” is bigger then 0, then jump and subtract 1 from the variable, and if you can’t jump while your variable jump is bigger then 0, then allow jumping again.
And when the player is on the floor, set the “jumps” variable back to 2 (which is the default amount).
However, when I jump 2 times with any player, I can’t jump anymore at all. (Note that this happens separately, when I jump 2 times with player 1 I can’t jump with player 1 anymore, but I can jump 2 times with player 2 (just so I can’t jump with player 2 anymore). -
Damaging
A lot to explain, but I’ll try to keep it short. Basically, what all of this does, is check if the player is in collision with a object that inflicts damage. If it is, and the object ID is different from the player’s ID (so the player doesn’t take damage to it’s own “damage objects”, then inflict damage.
However, at very specific times, in which I noted to be: when I inflict damage to the other player and create another “damage object”, then I get damaged to.
Related screenshots
Observation
Using this approach, the game works perfectly. However, considering I would have to repeat the same thing like, for each player, I think it really consumes the game’s memory, and I don’t consider it a optimized method. Is there any other method to replicate this in a more optimized manner? Thank you very much