playMaker

Author Topic: Reset objects in scene after respawn to checkpoint  (Read 4838 times)

alejandrorobledomejia

  • Playmaker Newbie
  • *
  • Posts: 5
Reset objects in scene after respawn to checkpoint
« on: June 30, 2015, 10:45:39 PM »
Hi guys so Im a bit confused here. I have a scene were my player jumps over a set of blocks that have rigid bodies with no gravity on them but super high levels of drag. This way my player jumps on top and the cubes slowly fall down, giving him just enough time to jump to the next cube before falling into abyss. Before my player jumps ontop of the first cube I have a checkpoint ( checkpoint works perfect - I'm using playmakers starter kit and its respawn logic ) My problem is when my player dies through this series of obstacles, he is reset back to the check point but all of my cubes (obstacles) are completely disorganized and I can't figure out an efficient way of resetting them all to the initial stage. I know that if I use I tween to "set position" and trigger this event when my player hits the kill zone I can get all oft the blocks to be set back into my desired coordinates before my player is respawnd to checkpoint, but this seems rather unconventional if I were to have 20- 30 or more cubes...... any ideas?

This applies to everything, all animations and special triggered events in my scene never really reset after my player dies, making it rather awkward when dying and trying to play the scene again.

thanks in advance!

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Reset objects in scene after respawn to checkpoint
« Reply #1 on: July 20, 2015, 09:24:36 AM »
So If I good understand, you not like to reload the full scene, because you use some other functions.

The Solution:

I think the easy way to reset just the map (the cubes), if you create a parent gameobject, select and move all map cubes inside this parent what you like to reset and after drag n drop this gameobject (what is contain your all moved cubes) in to the project folder.

With this, you create a prefab from your map.

Now you need just delete the current map what contain the cubes and simple create the copy prefab.

If you do this in one fms state, it will be changed in one frame, and the player will just see, that the map is reseted but in real, you delete the used map and create, replace with the original prefab.

crusenho

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Reset objects in scene after respawn to checkpoint
« Reply #2 on: June 04, 2021, 03:41:24 AM »
Thank you @Bqlqzs, that is good advice for creating a prefab of the parent and spawn them again after the player died.

In my scenario is also similar, but it works too.  Wanted to point it out and share some ideas.

1. A player touches a checkpoint.

2. After the checkpoint there are some enemies, the player kills all the enemies.

3. After the player kills the enemies, the player falls off a cliff and died.

4. The player gets respawn on the checkpoint and the enemies get respawn too.

5. And for example, if even though the player didn't kill those enemies and falls off a cliff, the player gets respawn on the checkpoint and the enemies too.

The Solution in my scene:

1. In the Player FSM, when the player dies do "Set Position 2D" to the checkpoint position.  This way is to get respawn the player on the checkpoint.

2. The enemy Game Objects must become Children on a Parent Game Object of enemies.  And create a Prefab of the Parent.

3. In the Parent Game Object set an FSM and do "Get Owner" to store a global variable.

4. In the Player FSM, when the Player dies do "Destroy Object" on the stored global variable.  This way is to delete the old enemies before the Player dies.

5. In the Player FSM, also add "Create Object" on the Game Object field put the prefab (not the global variable, but simply drag the prefab object from the asset).  In the "Create Object" I left everything to None except the Game Object.  This way is to get respawn of the new enemies after the Player dies.

Other Possibilities and Questions:
I haven't tried to solve them but here are my thoughts, and if there is anyone who can solve them please help to share some advices or answers.

1. What if there are coins you collect after the Player touches the checkpoint, and when the Player dies you need to restart the collected number.  So basically, respawn new coins and reset to the numbers before you have collected them when the Player dies.

2. How about XP Points you gain after killing enemies after the checkpoint, and the player dies.  And you need to reset the XP Points after you gain, does it work the same as the coins too?

3. Fall Platforms, that's included the previous reply and I think it makes sense too because spawning new objects meaning get reset to the default position.

4.  If you have any other possibilities or questions feel free to ask :)