2.11 crashing and respawning

This commit is contained in:
david 2025-02-09 10:40:16 +01:00
parent c311181e8b
commit 1438dc7784
2 changed files with 18 additions and 2 deletions

7
general/utils.cs Normal file
View file

@ -0,0 +1,7 @@
using Godot;
static class DeferredCalls {
public static void ReloadCurrentScene(this Node node) {
node.GetTree().CallDeferred("reload_current_scene");
}
}

View file

@ -34,11 +34,20 @@ public partial class Player : RigidBody3D
{
if (body.GetGroups().Contains("Goal"))
{
GD.Print("Player landed on the landing pad");
CompleteLevel();
}
if (body.GetGroups().Contains("Hazard"))
{
GD.Print("Player crashed on the floor :(");
CrashSequence();
}
}
private void CrashSequence(){
GD.Print("Player crashed on the floor :(");
DeferredCalls.ReloadCurrentScene(this);
}
private void CompleteLevel(){
GetTree().Quit();
}
}