Trouble respawning after death!
Hello again,
I have gotten my actor to change direction, shoot, move, jump, die; but I can't get him to respawn I have made my rules of- "If: game.SoldierHealth <= 0" -do- "Spawn actor: Explosion0" , "destroy". Then I added a "DEAD?" attribute in game and made it change to true. THEN I added an "If: game.SoldierHealth = 0" , "If: DEAD? = true" , "Receives a key press: r" -do- "Change Attribute: DEAD? -to- false" , "Change Attribute: game.SoldierHealth -to- 3". This didn't work. Then I did "If: game.DEAD? = true" , "Receives a key press: r" -do- "Change Scene -to- Tutorial". That didn't work either. I need help on respawning. @KillerPenguinStudios said I should change some attributes. I liked his idea but I tried multiple times and nothing has worked so far. If I could get any help that would be awesome
- Thanks
Comments
It sounds like you had a simple setup that didn't work and started adding attributes and conditions to try and fix it and now have made it overly complex. I've done that myself!
You'll want to rule out a problem with actor "instances." To do this, double-click on the actor on the scene and see if the lock symbol appears. If it does, then the actor is still using the original prototype rules. If it doesn't and you instead see a "Revert to Prototype" button at the top of the window, then you've created an instance of the actor with its own rules. The fix for this (and I recommend it either way since your actor isn't acting the way you expect) is to delete it from the scene and add it again. This will force it to be a prototype and use the correct rules.
Once you've done that, add a Log Debugging Statement and watch it in the Debugger window to make sure the rule you think should be firing is in fact firing. Lastly, simplify your rules so that you are only checking game.SoldierHealth ≤ 0 and then test again with a Log Debugging Statement. Is it possible your game.SoldierHealth never goes that low? Are you watching its value with a Display Text behavior on screen?
Your explanation was all about checking to see if the actor was "dead" and spawning an explosion. You haven't actually explained how you were trying to re-spawn the actor. Can you explain that?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes, @tatiang. What I want to do is when he is dead is for him to respawn if "r" is pressed and his health is equaling 0.
Oh, I am watching if he is dead I have a "true/false" display text.
What?! I just made a display text of my life! IT GOES TO -17! I did something wrong
Ok. Fixed that. But still having trouble.
If you are putting the respawn rule in the character actor then it won't fire since the actor will be destroyed before it fires the respawn rule.
Fortuna Infortuna Forti Una
That makes sense :agree:
So Mr. @Lovejoy, is there a way to fix this?
Just put the destroy actor on a short timer like 0.3 seconds. This will give the change attribute DEAD to true enough time to change over.
Fortuna Infortuna Forti Una
Thanks
Thanks a lot @Lovejoy. Oh, sorry if I was rude when I said Mr. Lovejoy. I wasn't trying to be rude
You're fine, no worries. Im glad i was able to help.
Fortuna Infortuna Forti Una
Hey @jdlcrater,
You were not specific when you first mentioned this. The only thing you said was, "I need a little help with reloading levels too. What I need help with is just reloading levels. I can do reload a reload scene button but my character will only re-spawn as an explosion(he explodes when dead)."
If you were originally more specific like you were in this post I would have given you more of the answer you were looking for. Your issues that you are facing is where you are placing your rules at, just as @Lovejoy had said.
I would not recommend doing what what @Lovejoy suggested as it is not the best way to do this. This may work but is asking for issues to happen and is not the most efficient way of doing this.
What you need to do is create another actor and call it something like "Controller". Turn it's Movement off. This is where you will place a lot of your rules that you want to happen in the scene. You will then place this actor in your corresponding scenes that it is needed. Put it off to the side, off screen so it is not seen. In here you can place your re-spawn rule for your character. You can tell it that if restart is true to spawn the character at the specified locations. I hope that makes sense.
One thing that I do that you could try if your feeling up to it is recycling actors rather than spawning and destroying them. Instead of destroying and spawning the player is when player is dead, turn it's alpha to 0. so he is not seen anymore. When restart is true, change players X and Y to it's starting position and change it's alpha back to 1. If you do this and your telling your player to change it's image to the death image, you will not see it as you told it to change it's alpha to 0. I would have the death image in the scene but off the screen and when it is needed I would tell it to change it's X and Y to the players X and Y, play the animation then after it is done to then change it's X and Y back to it's starting X and Y off the screen. Or you could simply just spawn the death image at the invisible players X and Y, play animation, then destroy.
I personally choose the above option as it gives you better performance. When ever I can I try not to spawn and destroy actors. One thing you can add in your rules if you decide to go the route of turning actors alpha to 0 is in the rules you can also add to follow through with the rules if it's alpha is 1. I know it's a lot but hope that all makes since and helps.
Killer Penguin Studios
@KillerPenguinStudios Okay. Thanks for that I think I like destroying him better than changing his alpha to 1. I did the GameSalad tutorial where I had to change the boss' color alpha to 0, but I could keep shooting him when he was dead. But I never thought of it like that. Plus, I am going to make the enemy hunt the player I will tell you how I did it though. I made the attribute to when he collides with deathground that his life goes to 0. If life = 0 then spawn actor explode0, and destroy this actor. Then to make him respawn, I made it if key receives a press: h -is- down, change attribute: life to 3, TIMER : after 3 seconds (of h being held down) reset scene
Hope that made sense
Oh! Yes, I also realized that I needed to make a respawn actor spawn when my character died. Because when he is dead he can't do much