Updated the locomotion script to fetch the settings from the current locomotion state
This commit is contained in:
parent
8ffb521e00
commit
d4a4b6ce4a
@ -5,7 +5,7 @@
|
|||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
|
|
||||||
## The locomotion settings of the current state.
|
## The locomotion settings of the current state.
|
||||||
@export var current_settings: LocomotionSettings
|
@export var state_machine: StateMachine
|
||||||
## The direction the actor wishes to move in.
|
## The direction the actor wishes to move in.
|
||||||
@export var wish_dir: Vector3
|
@export var wish_dir: Vector3
|
||||||
## The height the head attachment should be placed at according to the collider height.
|
## The height the head attachment should be placed at according to the collider height.
|
||||||
@ -15,9 +15,14 @@ extends CharacterBody3D
|
|||||||
@onready var locomotion_collider: CollisionShape3D = $LocomotionCollider
|
@onready var locomotion_collider: CollisionShape3D = $LocomotionCollider
|
||||||
@onready var shape_cast: ShapeCast3D = $ShapeCast3D
|
@onready var shape_cast: ShapeCast3D = $ShapeCast3D
|
||||||
|
|
||||||
|
func get_current_settings() -> LocomotionSettings:
|
||||||
|
if state_machine.CURRENT_STATE is LocomotionState:
|
||||||
|
return state_machine.CURRENT_STATE.settings
|
||||||
|
return null
|
||||||
|
|
||||||
func accelerate(max_velocity: float, delta: float) -> Vector3:
|
func accelerate(max_velocity: float, delta: float) -> Vector3:
|
||||||
var current_speed = velocity.dot(wish_dir)
|
var current_speed = velocity.dot(wish_dir)
|
||||||
var add_speed = clamp(max_velocity - current_speed, 0, current_settings.MAX_ACCELERATION * delta)
|
var add_speed = clamp(max_velocity - current_speed, 0, get_current_settings().MAX_ACCELERATION * delta)
|
||||||
return velocity + add_speed * wish_dir
|
return velocity + add_speed * wish_dir
|
||||||
|
|
||||||
func update_velocity(delta: float, apply_friction: bool = true) -> Vector3:
|
func update_velocity(delta: float, apply_friction: bool = true) -> Vector3:
|
||||||
@ -26,10 +31,10 @@ func update_velocity(delta: float, apply_friction: bool = true) -> Vector3:
|
|||||||
var speed = velocity.length()
|
var speed = velocity.length()
|
||||||
|
|
||||||
if speed != 0:
|
if speed != 0:
|
||||||
var control = max(current_settings.STOP_SPEED, speed)
|
var control = max(get_current_settings().STOP_SPEED, speed)
|
||||||
var drop = control * current_settings.FRICTION * delta
|
var drop = control * get_current_settings().FRICTION * delta
|
||||||
velocity *= max(speed - drop, 0) / speed
|
velocity *= max(speed - drop, 0) / speed
|
||||||
return accelerate(current_settings.MAX_VELOCITY, delta)
|
return accelerate(get_current_settings().MAX_VELOCITY, delta)
|
||||||
|
|
||||||
func update_step_collider_position():
|
func update_step_collider_position():
|
||||||
var step_shape: SeparationRayShape3D = step_collider.shape
|
var step_shape: SeparationRayShape3D = step_collider.shape
|
||||||
@ -54,7 +59,7 @@ func has_collision_above(h: float) -> bool:
|
|||||||
## Needs a cleanup pass
|
## Needs a cleanup pass
|
||||||
var duration: float = .5
|
var duration: float = .5
|
||||||
var elapsed_time = 0.0
|
var elapsed_time = 0.0
|
||||||
func update_collider_height(delta: float, h: float = current_settings.HEIGHT) -> bool:
|
func update_collider_height(delta: float, h: float = get_current_settings().HEIGHT) -> bool:
|
||||||
var t = clamp(elapsed_time / duration, 0, 1)
|
var t = clamp(elapsed_time / duration, 0, 1)
|
||||||
var current_collider_shape: CylinderShape3D = locomotion_collider.shape
|
var current_collider_shape: CylinderShape3D = locomotion_collider.shape
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user