Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Respawn when falling out of bounds

Discussion in 'Open Projects' started by iMakega, Feb 14, 2021.

  1. iMakega

    iMakega

    Joined:
    Apr 12, 2020
    Posts:
    3
  2. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey @iMakega, we don't assign tasks to people. Feel free to give it a shot, and we'll evaluate the PR. Please use this thread to discuss your ideas if you have doubts.
     
  3. zvervo

    zvervo

    Joined:
    Jan 5, 2017
    Posts:
    6
    Hey,

    just make some rough time based detection of falling out of map, and teleporting protagonist to default spawn location. It's definetely not done, its just basic kick-off, which I make to get familiar with the game, contribution system, ... , and github.

    So if @iMakega have some idea, how to implement whole "system", I can help him to implement that idea.


    ---

    https://github.com/UnityTechnologies/open-project-1/pull/369
     
    Last edited: Feb 14, 2021
    cirocontinisio likes this.
  4. ontrigger

    ontrigger

    Joined:
    Oct 31, 2016
    Posts:
    24
    Gave this one a go @ https://github.com/UnityTechnologies/open-project-1/pull/381

    Added a TeleportIfOOB action on the falling state that will check the ground below player after a set amount of time falling. If there is no ground found, then teleport to the last valid grounded position (updated only in the walking state).

    Is it better to respawn the player instead or is this solution good enough?
     
  5. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Honestly not a super fan of the "respawn after a set amount of time". Feels like we would need to fine tune the time so that it's not too much and not too little.
    Why not a specific collider that "kills" the player? Seems to me like a solution that is easier to control. I might be wrong!
     
    archila1987 likes this.
  6. ontrigger

    ontrigger

    Joined:
    Oct 31, 2016
    Posts:
    24
    I don't really understand the need to fine tune the time at all or control when the player gets respawned. It's not like a player would expect to respawn at a specific height after falling. It's not a gameplay important mechanic, but rather a failsafe system.
    Besides, having to place a killplane on each level is tedious, and the level designer could just forget to do that.
    Though now that I think about it, 5 seconds of falling that I set in the PR is indeed too long, by that point the player might just quit to main menu and restart (if that's a thing). 3 seconds of falling sounds perfect to me.
     
    nogamewithoutbrain likes this.
  7. mattpriem

    mattpriem

    Joined:
    Aug 3, 2020
    Posts:
    1
    Hello. I'm new to Unity (about 6 months), but I'd like to contribute.
    Here's the solution I'm exploring...

    1: create a KillPlane, and create a KillOnTouch script.
    2: KillOnTouch will do something like...
    if ( ! falling) {
    store players transform.position
    }
    if player collider intersects KillPlane collider
    send player back to stored location. plus or minus some buffer to make sure player is not right on edge/cliff.

    3: make KillPlane with script a prefab, so level designer can drop it in their scene and adjust the height appropriately.

    I thought I'd check in with the community before I started coding this solution. Any thoughts?
     
  8. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    The issue is, if the player jumps in the water in 3 seconds of falling they would be waaaaay below the sea floor plane, as gravity adds speed up very fast.
     
  9. nogamewithoutbrain

    nogamewithoutbrain

    Joined:
    Jan 26, 2019
    Posts:
    1
    Hi

    I might be wrong but I don't see @ontrigger solution pushed. From my point of view, this is the best solution available as we don't need any setup in scenes (in case of colliders) nor fine tuning DeathHeight value that would require a constraint on level design creation (for instance all terrain above -100). We avoid manual error this way.

    And I think the question of fine tuning the time before check is not a problem. If there is ground under the player, the logic is just going to keep player movement. In case there is no ground under player legs, it triggers respawn. So we can even check that each 0.5sec while character is jumping. Its purpose is just to not check every frame.

    Ludo :)
     
    ontrigger and Smurjo like this.
  10. EduardoBastos

    EduardoBastos

    Joined:
    Oct 11, 2017
    Posts:
    7
    Hello there!
    It seems that no solution to this problem has not yet been pushed. I will try to tackle this problem using the "Kill Plane" approach, as I think it is more adaptable to the needs of every envoironment, and allows for the designer to determine where the player should be falling to. But I am not sure if the player should be respawned in the last safe ground he was in, or in the initial spawn point of the scene.
     
  11. EduardoBastos

    EduardoBastos

    Joined:
    Oct 11, 2017
    Posts:
    7
    Hello,
    So I tought about making a "OnPlayerKilled" event that fires when the player touches the Kill Plane, and have this event trigger a universal "RespawnPlayer" function. I would like to use the same function that is used when the player dies in combat, but I can find no class that subscribes to the UnityAvtion "OnDie" from Damageable.cs, so I cant find this Respawn function. Can anyone point me towards it? Thank you very much!
     
  12. RivanParmar

    RivanParmar

    Joined:
    Apr 24, 2020
    Posts:
    7
    I would suggest adding colliders all around the plane and the ones near areas with water should be separate from others. So that the player can't go out of bounds of the plane. And when it goes out of bounds of water by touching the collider near the water, just fire an event and respawn it near the edge of water by adding particular amount of translation in the x or y axis of the player, so that it respawns exactly near the surface perpendicular to where it died.
     
  13. randomscribe

    randomscribe

    Joined:
    Jun 14, 2021
    Posts:
    29
    What's the status on this issue? I see a couple open PRs for it -- do those require additional work before they're ready to merge?
     
  14. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Actually, I think this is a "solved problem". In the game we have this system of entry/exit points for locations, which we can reuse to provide this functionality. If you check the scene TownUpper, you will see a bunch of these exit points that act as a "catcher" if the player jumps down. Some of them lead to TownInner, some to TownMarket, some to ForestEntrance, depending on where you jump from. But we can put them in the water (for instance) and have them reload the same scene. The biggest challenge is placing them so they match the shape of the shore, there will be some Probuilding to do...