Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    733
    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:
    2
    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

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    733
    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!
     
  6. ontrigger

    ontrigger

    Joined:
    Oct 31, 2016
    Posts:
    2
    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

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    733
    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!
     
unityunity