How do I respawn a player after he dies?

0 favourites
From the Asset Store
Players follower. use it for anything which follows the player
  • I know how to reset the entire layout, but I can't figure out how to create an event where he spawns back to a safe spot. The game in question is a platformer. I also have instances where the player will be killed by enemies, and will need to spawn again. Any help would be so awesome

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What i would do is to actually never destroy the player. When he is suppose to be "dead" i would take him out of the screen (set x,y), and when i want him to be back, i would set his x,y back to wherever i want to.

    This also allows you to manage better the instance variables of the player, if he has them.

  • That sounds like a great idea. However, how do I set the x, y back to a safe point automatically? Or do I have to create safe points all across the map?

  • What i would do is make a sprite called CheckpointNode or something of that nature

    Then maybe a instance variable on the player like "Lives" (give it a number of course for example 3)

    and when the player is supposed die/lose a life you can subtract a life and set the X/Y to CheckpointNode.

    If you have multiple CheckpointNodes you can make a variable to hold which checkpoint the player touched last so you can send him back to the right checkpoint.

    I probably said more that I should have hope I helped

  • Haha how is that saying more than you should have? It helps quite a bit, thank you. I'll try to see how that would work.

  • Went out my way for you bro here you are lol <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    https://dl.dropboxusercontent.com/u/258 ... ample.capx

    Also I figured people searching the forums might come across a similar issue and want to know how to do it.

  • Holy. Crap. This is freaking perfect. Thanks so much dude! And I imagine it would work just fine even if I gave the player unlimited lives, correct? i.e. getting rid of the "subtract 1 life from player" line?

  • yea if you want unlimited lives just remove the instance variable on the player and delete that line (for optimization purpose)

  • Wonderful. Thanks so much man. This is a great headstart for me.

  • Quick question again. When my player spawns at the checkpoints he freaks out and shakes violently before landing on the ground and becoming playable again. Have I done something wrong? I basically copied everything from your event sheet and wrote it in mine.

  • I think when he is teleported , the collision box of the player is in the ground , causing some undefined behavior , kinda like the same as if you were teleported in the ground , then physics would be all no way and something funky would happen, try moving the checkpoints around a bit to give some space for the player to respawn

  • Nope, it still does it regardless of where I place the node. On the ground, in the sky, under the ground, etc. I've moved it all over the place, but the player still freaks out for a second.

  • Wait, I figured something out. I originally had the player disabled, system wait for 1 second, spawn, and then player enabled. I took out the system wait and now the player spawns just fine, however, I need the system to wait for a second before spawning, so it looks smooth.

  • LoganJFord Preety neat. I was working on a solution to do just that in my game but yours is way cleaner than mine was.

  • swordofsolace hmm... can't you just hide the player on spawn for one second and then show him?

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)