commit 35303cd2bf751645255911f7ce9c1057e1d50b63
parent 7571b27c9c94bed888d72a89cdd6a16ee1a99dd3
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Tue, 21 Sep 2021 23:17:47 +0300
Complete the switch to RayCast detection of floor.
Diffstat:
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/Constants.gd b/Constants.gd
@@ -20,12 +20,14 @@ extends Node
const on_floor_maximum_distance := 0.1
+
+# width, height, depth
const road_box_dimensions: Vector3 = Vector3(0.35, 0.5, 0.95)
const fall_acceleration: float = 50.0
const on_the_floor_fall_acceleration: float = 1.0
-const jump_impulse: float = 10.0
+const jump_impulse: float = 8.0
const maximum_forward_speed: float = 20.0
const forward_speed_increment: float = 0.5
const side_speed: float = 1.0
diff --git a/Player.gd b/Player.gd
@@ -63,7 +63,7 @@ func _physics_process(delta: float) -> void:
var collider := collision.collider
if collider.is_in_group("goal"):
emit_signal("reached_goal")
- if on_floor_flag:
+ if near_floor:
direction = 0
if (
(not Input.is_action_just_pressed("ui_right")) or
@@ -116,11 +116,8 @@ func _physics_process(delta: float) -> void:
velocity.x = direction * Constants.side_speed
velocity.z = -driving_speed
- if is_on_floor():
- on_floor_flag = true
- if on_floor_flag and Input.is_action_just_pressed("jump"):
+ if near_floor and Input.is_action_just_pressed("jump"):
velocity.y += Constants.jump_impulse
- on_floor_flag = false
if near_floor:
velocity.y -= Constants.on_the_floor_fall_acceleration * delta
else: