From 6316952ca524cd1e16bc0b49354c1aace7ed3ddd Mon Sep 17 00:00:00 2001 From: unfa Date: Sat, 22 May 2021 02:10:00 +0200 Subject: [PATCH] Attempt at fixing player ledge jump glitch --- Game/Assets/Characters/Player.gd | 3 ++- Game/Assets/Characters/Player.tscn | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Game/Assets/Characters/Player.gd b/Game/Assets/Characters/Player.gd index b3f98e2..dfbc4a5 100644 --- a/Game/Assets/Characters/Player.gd +++ b/Game/Assets/Characters/Player.gd @@ -4,6 +4,7 @@ extends KinematicBody3D #var speed := 15 @onready var head = $Head +@onready var ground_check = $GroundCheck var direction := Vector3.ZERO var accel := 0 @@ -54,7 +55,7 @@ func _input(event) -> void: func _physics_process(delta): direction = Vector3.ZERO - if is_on_floor(): + if is_on_floor() and ground_check.is_colliding(): snap = -get_floor_normal() medium = "ground" gravity_vec = Vector3.ZERO diff --git a/Game/Assets/Characters/Player.tscn b/Game/Assets/Characters/Player.tscn index 7c5321e..458ee36 100644 --- a/Game/Assets/Characters/Player.tscn +++ b/Game/Assets/Characters/Player.tscn @@ -15,7 +15,7 @@ radius = 0.25 height = 0.5 [node name="Player" type="KinematicBody3D"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2, 0 ) script = ExtResource( 1 ) [node name="Mesh" type="MeshInstance3D" parent="."] @@ -45,3 +45,9 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.9, 0 ) shape = SubResource( 3 ) disabled = true script = null + +[node name="GroundCheck" type="RayCast3D" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, 0 ) +target_position = Vector3( 0, -1.1, 0 ) +debug_shape_thickness = 5.0 +script = null