diff options
Diffstat (limited to 'character/fps_controller/fps_controller.gd')
-rw-r--r-- | character/fps_controller/fps_controller.gd | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index 9c4e7c3..ecd8871 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -2,6 +2,7 @@ extends KinematicBody onready var camera = $Camera onready var ray = $Camera/RayCast +onready var ladder_area = $ladder_detector export var walk_speed : int = 10 export var accel : float = 0.2 @@ -11,14 +12,7 @@ export var jump_strength : int = 20 export var inertia : int = 5 var velocity : Vector3 - -var state = WALKING - -enum { - WALKING, - SPRINTING, -} - +var is_climbing : bool = false func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -38,8 +32,12 @@ func get_input(): if Input.is_action_pressed("forward"): dir += -global_transform.basis.z + if is_climbing: + dir += global_transform.basis.y if Input.is_action_pressed("backward"): dir += global_transform.basis.z + if is_climbing: + dir += -global_transform.basis.y if Input.is_action_pressed("left"): dir += -global_transform.basis.x if Input.is_action_pressed("right"): @@ -49,14 +47,18 @@ func get_input(): #Pull X and Z values from directional input. Velocity.y will be handled in physics loop + if is_climbing: + velocity.y = lerp(velocity.y, dir.y * walk_speed, accel) + velocity.x = lerp(velocity.x, dir.x * walk_speed, accel) velocity.z = lerp(velocity.z, dir.z * walk_speed, accel) func handle_movement(): #Apply gravity - velocity.y += gravity - if velocity.y < term_velocity: - velocity.y = term_velocity + if !is_climbing: + velocity.y += gravity + if velocity.y < term_velocity: + velocity.y = term_velocity velocity = move_and_slide(velocity, Vector3.UP, true, 4, PI/4, false) @@ -83,3 +85,13 @@ func handle_collision(): # So to add force at collision position, substract colliders pos from collision.position var col_pos = collision.position - collider.transform.origin collider.add_force(col_force_vec, col_pos) + + +func _on_ladder_detector_body_entered(body): + if body.is_in_group("ladder"): + is_climbing = true + + +func _on_ladder_detector_body_exited(body): + if body.is_in_group("ladder"): + is_climbing = false |