Skip to content

Commit

Permalink
Merge pull request #117 from FailSpy/ladder_improvements
Browse files Browse the repository at this point in the history
Ladder collision fixes and buffer timer
  • Loading branch information
Phazorknight authored Mar 13, 2024
2 parents e242fd2 + 544c517 commit bde8798
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion COGITO/PrefabScenes/ladder.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ shadow_mesh = SubResource("ArrayMesh_s5jyy")
[sub_resource type="BoxShape3D" id="BoxShape3D_xagqk"]
size = Vector3(0.8, 3.03359, 0.1)

[node name="Ladder" type="Area3D"]
[node name="Ladder" type="Area3D" node_paths=PackedStringArray("ladder_collision")]
transform = Transform3D(-2.98023e-08, 0, -1, 0, 1, 0, 1, 0, -2.98023e-08, -18.4395, 1.6, -4.87125)
script = ExtResource("1_odht7")
ladder_collision = NodePath("ladder")

[node name="ladderArea" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0)
Expand Down
11 changes: 10 additions & 1 deletion COGITO/Scripts/ladder_area.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
extends Area3D

@export var ladder_collision : CollisionObject3D
var original_process_mode : ProcessMode

func _ready():
body_shape_entered.connect(_on_body_shape_entered)
body_exited.connect(_on_body_exited)

if ladder_collision:
original_process_mode = ladder_collision.process_mode

func _on_body_shape_entered(body_rid,body,body_shape_idx,local_shape_idx):
if body.is_in_group("Player"):
Expand All @@ -14,9 +18,14 @@ func _on_body_shape_entered(body_rid,body,body_shape_idx,local_shape_idx):
var ladderDir = (local_shape_node.global_position - global_position).normalized()

body.enter_ladder(local_shape_node,ladderDir)
if body.on_ladder and ladder_collision:
original_process_mode = ladder_collision.process_mode
ladder_collision.process_mode = Node.PROCESS_MODE_DISABLED


func _on_body_exited(body):
if body.is_in_group("Player"):
#print("Exited ladder")
body.on_ladder = false
if ladder_collision:
ladder_collision.process_mode = original_process_mode
12 changes: 10 additions & 2 deletions COGITO/Scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ const WALL_MARGIN : float = 0.001

@export_group("Ladder Handling")
var on_ladder : bool = false
@export var CAN_SPRINT_ON_LADDER = false
@export var CAN_SPRINT_ON_LADDER : bool = false
@export var LADDER_SPEED : float = 2.0
@export var LADDER_SPRINT_SPEED : float = 3.3
@export var LADDER_COOLDOWN : float = 0.5
const LADDER_JUMP_SCALE : float = 0.5
var ladder_on_cooldown : bool = false

@export_group("Gamepad Properties")
@export var JOY_DEADZONE : float = 0.25
Expand Down Expand Up @@ -288,6 +290,9 @@ func params(transform3d, motion):
func test_motion(transform3d: Transform3D, motion: Vector3) -> bool:
return PhysicsServer3D.body_test_motion(self_rid, params(transform3d, motion), test_motion_result)

func ladder_buffer_finished():
ladder_on_cooldown = false

func enter_ladder(ladder: CollisionShape3D, ladderDir: Vector3):
# called by ladder_area.gd

Expand All @@ -299,6 +304,9 @@ func enter_ladder(ladder: CollisionShape3D, ladderDir: Vector3):
var offset = (global_position - ladder.global_position)
if offset.dot(ladderDir) < -0.1:
global_translate(ladderDir*offset.length()/4.0)
var ladder_timer = get_tree().create_timer(LADDER_COOLDOWN)
ladder_timer.timeout.connect(ladder_buffer_finished)
ladder_on_cooldown = true
on_ladder = true
return

Expand Down Expand Up @@ -351,7 +359,7 @@ func _process_on_ladder(_delta):
move_and_slide()

#Step off ladder when on ground
if is_on_floor():
if is_on_floor() and not ladder_on_cooldown:
on_ladder = false

var jumped_from_slide = false
Expand Down

0 comments on commit bde8798

Please sign in to comment.