]> Untitled Git - lightcycles.git/blobdiff - player/player.gd
Updated export config
[lightcycles.git] / player / player.gd
index 42300fe01e7e1816ea91e5eded1fc58742cd98c1..3cd1522f7d8371ba893fb418117173c18abbe771 100644 (file)
@@ -8,6 +8,7 @@ signal playerRestart
 
 
 @onready var _skin = $skin
+@onready var _ray = $RayCast3D
 
 
 @export_category("Appearance")
@@ -51,10 +52,18 @@ func _physics_process(_delta: float) -> void:
        if _state == state.ALIVE:
                velocity = global_transform.basis.z * speed
                move_and_slide()
-               if velocity.length() == 0:
+               if _ray_intersect_length() < 0.05 or velocity.length() < 0.02:
                        _explode()
 
 
+func _ray_intersect_length() -> float:
+       if _ray.is_colliding():
+               var point: Vector3 = _ray.get_collision_point()
+               var v: Vector3 = _ray.global_position - point
+               return v.length()
+       else:
+               return INF
+
 func _explode() -> void:
        _skin.visible = false
        _state = state.DEAD