Skip to content

Commit

Permalink
Add stair detecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Janorico committed May 21, 2023
1 parent 331a44b commit 71b0976
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scenes/game/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ mesh = SubResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 2 )

[node name="StairDetector" type="RayCast" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.8, 0 )
enabled = true
cast_to = Vector3( 0, 0, -2 )

[node name="CameraBase" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0 )

Expand Down
3 changes: 3 additions & 0 deletions scripts/game/Player.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class_name Player
extends KinematicBody

onready var stair_detector: RayCast = $StairDetector
onready var camera = $CameraBase/Camera
onready var camera_base = $CameraBase
onready var raycast = $CameraBase/Camera/RayCast
Expand Down Expand Up @@ -88,6 +89,8 @@ func _physics_process(delta):

if Input.is_action_pressed("forward"):
direction -= camera_base_basis.z #forward is negative in Godot
if stair_detector.is_colliding() and is_on_floor():
velocity.y = jump_vel * power_multipler
if Input.is_action_pressed("backward"):
direction += camera_base_basis.z

Expand Down

0 comments on commit 71b0976

Please sign in to comment.