Context: (and MAYBE too much of it)
My game has a mechanic where you can “infect” the body of an enemy, which will make that enemy the new player.
Originally, to do this I had individual events to swap between player to enemy, so for example there would be separate events for “Infect Enemy 1, as Player” “Infect Enemy 2, as Player”, and “Infect Player as Enemy 1” and so on. Each of these events only de/activated the top down movement behavior and toggled a “IsInfected” boolean.
And then for every reference of the player I instead used an object group that contained all players and enemies, so there would not have to be separate events for wasd movement for each and every enemy, among other things.
Unfortunately, this still brought up a bunch of bugs. All of the bugs were seemed to be impossible to fix, without fundamentally changing the entire system… So I did just that.
I restarted development of the entire game, on a separate project.
Instead of individual events like before i am using this:
(Ignore the red underline, i later deleted the enemy)
This system appears to work, and I do not think it is the problem, but on top of that change, I also made every single event a sub-event of this:
With that change, once you infect an enemy, the entire code shuts down… and I think its because this condition is only checking for the default player or something along those lines.
Soooo… My question is…
How could I have a player switching mechanic where the players you are switching to, can have multiple instances? I think that is technically what I’m trying to do.
I hope this wasnt too much information, but I felt the need to provide my thought process, or whatever that was.
Why have player switching mechanics? You could add all the enemy sprites as animations to your player object, and then use the animation of the enemy just infected. No need to have a load of events for each enemy. Just set the animation and go.
If you have mulitple animations per enemy character ( say one for walking, attack, idle etc), then you could name each one as _, and add a string variable to the player object that keeps track of the enemytype.
So say your first enemy object is named Zombie1. You’d set player variable enemyType to “Zombie1”. The player animations for the Zombie1 would be named “Zombie1_attack”, “Zombie1_walk” etc.
Then when you set an animation, say for attack, you’d just change the player animation by name, setting it to
player.VariableString(enemyType) + "_attack".
No need for more collision checks, no setting behaviours on and off. A lot simpler and cleaner.
@MrMen Great idea, I spent a while thinking over a better way to do this and never once considered that!
Thanks, can’t believe I didn’t think of that. I think the only problem is that I also want to leave behind the body of the thing you were controlling last. But… I think I could still find a way to do that, or scrap that specific mechanic because its not the most important.
When MrMen mentioned this I thought about that exactly. One thing you could do is right when the switch is going to happen, create another instance of the old character at the exact x and y of the player. Then you could hide the player, move its position to the new character, delete the new character, change the animation of the player to the new character, and then show the player again. So it would look like the player literally jumped bodies. It sounds complicated but I think it could be done fairly easily.
Create another object with the body of each players and enemies as it’s animations. I’m assuming you just need one image per character. No controls onit, no cillision detection - it becomes part of the scenery.