Reorganise player controller exports and add some new ones in preparation for new move mechanics

This commit is contained in:
Jarrod Doyle 2024-02-25 12:21:25 +00:00
parent 89ec939325
commit 050a897cad
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 14 deletions

View File

@ -2,22 +2,31 @@ class_name Player extends PhysicsBody3D
enum MovementType { VERTICAL, LATERAL } enum MovementType { VERTICAL, LATERAL }
@export var jump_speed := 4.5 #region Exports
@export var max_speed := 8
@export var slow_speed := 2
@export var mouse_sensitivity := 0.002 # radians/pixel @export var mouse_sensitivity := 0.002 # radians/pixel
## The character will be blocked from moving up slopes steeper than this angle @export_group("Movement")
## The character will be not be flagged as 'grounded' when stood on slopes steeper than this angle @export var slope_limit := 45.0
@export var slope_limit: float = 45
## The character will automatically adjust height to step over obstacles this high
@export var step_height := 0.2 @export var step_height := 0.2
## When grounded, the character will snap down this distance
## This keeps the character on steps, slopes, and helps keep behaviour consistent
@export var snap_to_ground_distance := 0.2 @export var snap_to_ground_distance := 0.2
@export_subgroup("Crouching")
@export var crouch_height_decrease := 1.0
@export var crouch_speed := 2.0
@export var crouch_acceleration_time := 0.5
@export var crouch_deceleration_time := 0.2
@export_subgroup("Running")
@export var run_speed := 8.0
@export var run_acceleration_time := 1.5
@export var run_deceleration_time := 0.5
# TODO Change jumping to take a height, time-to-peak, and time-to-ground. Gravity can be worked out from that
@export_subgroup("Jumping")
@export var jump_speed := 4.5
@export var jump_pre_grace_time := 0.1
@export var jump_post_grace_time := 0.1
@export_group("Connector Nodes") @export_group("Connector Nodes")
@export var head: Node3D @export var head: Node3D
@export var body: Node3D @export var body: Node3D
@ -60,6 +69,8 @@ enum MovementType { VERTICAL, LATERAL }
## accurate. 4 is a decent number for low poly terrain! ## accurate. 4 is a decent number for low poly terrain!
@export var max_iteration_count := 4 @export var max_iteration_count := 4
#endregion
var gravity := 9.8 var gravity := 9.8
var _velocity: Vector3 = Vector3() var _velocity: Vector3 = Vector3()
var grounded: bool = false var grounded: bool = false
@ -417,7 +428,7 @@ func _vert(value: Vector3) -> Vector3:
func _on_grounded_state_physics_processing(delta: float) -> void: func _on_grounded_state_physics_processing(delta: float) -> void:
var move_speed := max_speed if Input.is_action_pressed("cc_sprint") else slow_speed var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var target_velocity_h := get_move_dir() * move_speed var target_velocity_h := get_move_dir() * move_speed
var target_velocity_v := -gravity * delta var target_velocity_v := -gravity * delta
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y) var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
@ -430,7 +441,7 @@ func _on_grounded_state_physics_processing(delta: float) -> void:
func _on_falling_state_physics_processing(delta: float) -> void: func _on_falling_state_physics_processing(delta: float) -> void:
var move_speed := max_speed if Input.is_action_pressed("cc_sprint") else slow_speed var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var target_velocity_h := get_move_dir() * move_speed var target_velocity_h := get_move_dir() * move_speed
var target_velocity_v := _velocity.y - gravity * delta var target_velocity_v := _velocity.y - gravity * delta
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y) var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
@ -441,7 +452,7 @@ func _on_falling_state_physics_processing(delta: float) -> void:
func _on_jumping_state_physics_processing(delta: float) -> void: func _on_jumping_state_physics_processing(delta: float) -> void:
var move_speed := max_speed if Input.is_action_pressed("cc_sprint") else slow_speed var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var target_velocity_h := get_move_dir() * move_speed var target_velocity_h := get_move_dir() * move_speed
var target_velocity_v := jump_speed var target_velocity_v := jump_speed
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y) var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)