- Project updated to support the new CharacterBody3D node structure.
- PlayerMovementHandler updated to properly use physics process root motion.
This commit is contained in:
@@ -3,6 +3,7 @@ extends Node
|
||||
|
||||
@export_category("Nodes")
|
||||
@export var character : Character3D
|
||||
@export var body : CharacterBody3D
|
||||
@export var player_camera : PlayerCamera3D
|
||||
@export var slice_ring_spawner : SliceRingSpawner
|
||||
|
||||
@@ -27,7 +28,7 @@ extends Node
|
||||
|
||||
var _target_movement_vector : Vector2 = Vector2.ZERO
|
||||
var _current_movement_speed : float = 0.0
|
||||
var _lateral_motion_accumulator : Vector3 = Vector3.ZERO
|
||||
var _physics_motion_accumulator : Vector3 = Vector3.ZERO
|
||||
var _gravity : float = 0.0
|
||||
|
||||
var _slice_time_aim_blend : float = 0.0
|
||||
@@ -58,24 +59,23 @@ func _on_slice_time_released() -> void:
|
||||
|
||||
|
||||
func _on_walking_state_entered() -> void:
|
||||
_lateral_motion_accumulator = Vector3.ZERO
|
||||
_physics_motion_accumulator = Vector3.ZERO
|
||||
_gravity = 0.0
|
||||
emit_signal("state_changed", "walk")
|
||||
func _on_coyote_time_state_entered() -> void:
|
||||
_on_walking_state_entered()
|
||||
|
||||
func _on_walking_state_processing(_delta:float) -> void:
|
||||
_root_motion_walk_process(_delta)
|
||||
_camera_relative_heading_process(_delta)
|
||||
func _on_coyote_time_state_processing(_delta: float) -> void:
|
||||
_on_walking_state_processing(_delta)
|
||||
|
||||
func _on_walking_state_physics_processing(_delta:float) -> void:
|
||||
_root_motion_walk_process(_delta)
|
||||
_lateral_movement_physics_process(_delta)
|
||||
#_gravity_physics_process(_delta)
|
||||
_move_character()
|
||||
|
||||
if !character.is_on_floor():
|
||||
if !body.is_on_floor():
|
||||
_state_chart.send_event("fall")
|
||||
_gravity = 0.0
|
||||
func _on_coyote_time_state_physics_processing(_delta: float) -> void:
|
||||
@@ -84,7 +84,7 @@ func _on_coyote_time_state_physics_processing(_delta: float) -> void:
|
||||
|
||||
func _on_falling_state_entered() -> void:
|
||||
_gravity = 0.0
|
||||
_lateral_motion_accumulator = character.velocity
|
||||
_physics_motion_accumulator = body.velocity
|
||||
|
||||
func _on_falling_state_processing(_delta:float) -> void:
|
||||
_camera_relative_heading_process(_delta)
|
||||
@@ -95,7 +95,7 @@ func _on_falling_state_physics_processing(_delta:float) -> void:
|
||||
_gravity_physics_process(_delta)
|
||||
_move_character()
|
||||
|
||||
if character.is_on_floor():
|
||||
if body.is_on_floor():
|
||||
_state_chart.send_event("land")
|
||||
|
||||
|
||||
@@ -123,13 +123,13 @@ func _on_slice_time_state_exited() -> void:
|
||||
player_camera.state_chart.send_event("no_more_slice_time")
|
||||
|
||||
func _on_slice_time_state_processing(_delta:float) -> void:
|
||||
_root_motion_accumulation_process(_delta)
|
||||
character.character_skeleton.animation_tree["parameters/slice_time/slice_time_idle/slice_time_pitch/seek_request"] = _slice_time_tilt
|
||||
#character.character_skeleton.animation_tree["parameters/slice_time_active/aim_angle/seek_request"] = 0.0
|
||||
|
||||
func _on_slice_time_state_physics_processing(_delta:float) -> void:
|
||||
_lateral_movement_physics_process(_delta)
|
||||
_move_character()
|
||||
#_lateral_movement_physics_process(_delta)
|
||||
#_move_character()
|
||||
pass
|
||||
|
||||
func _on_slice_time_aim_state_entered() -> void:
|
||||
var _slice_time_input : InputAction = _player_movement_standard.find_input_action("slice_time")
|
||||
@@ -153,19 +153,19 @@ func _on_slice_time_aim_state_physics_processing(_delta:float) -> void:
|
||||
func _on_slice_time_slice_state_entered() -> void:
|
||||
pass
|
||||
|
||||
func _on_slice_time_slice_state_processing(_delta:float) -> void:
|
||||
_on_slice_time_aim_state_processing(_delta)
|
||||
|
||||
func _on_slice_time_slice_state_physics_processing(_delta:float) -> void:
|
||||
_on_slice_time_aim_state_physics_processing(_delta)
|
||||
|
||||
|
||||
func _move_character():
|
||||
character.move_and_slide()
|
||||
body.move_and_slide()
|
||||
|
||||
func _root_motion_walk_process(_delta:float) -> void:
|
||||
_current_movement_speed = lerpf(_current_movement_speed, _target_movement_vector.length_squared(), clampf(_delta * _walk_reaction_speed, 0.0, 1.0))
|
||||
character.character_skeleton.animation_tree["parameters/walk/blend_position"] = _current_movement_speed
|
||||
_root_motion_accumulation_process(_delta)
|
||||
|
||||
func _root_motion_accumulation_process(_delta:float) -> void:
|
||||
var root_motion_speed : Vector3 = character.quaternion * character.character_skeleton.animation_tree.get_root_motion_position()
|
||||
if root_motion_speed.length_squared() >= 0.00000000:
|
||||
_lateral_motion_accumulator += root_motion_speed
|
||||
|
||||
func _camera_relative_heading_process(_delta:float):
|
||||
var _target_movement_length_squared : float = _target_movement_vector.length_squared()
|
||||
@@ -176,15 +176,16 @@ func _camera_relative_heading_process(_delta:float):
|
||||
character.quaternion = character.quaternion.slerp(_camera_relative_rotation, clampf(_delta * _walk_turn_speed, 0.0, 1.0))
|
||||
|
||||
func _lateral_movement_physics_process(_delta:float) -> void:
|
||||
character.velocity = _lateral_motion_accumulator / _delta
|
||||
_lateral_motion_accumulator = Vector3.ZERO
|
||||
var root_motion_speed : Vector3 = character.quaternion * character.character_skeleton.animation_tree.get_root_motion_position()
|
||||
if root_motion_speed.length_squared() >= 0.00000000:
|
||||
body.velocity = root_motion_speed / _delta
|
||||
|
||||
func _physics_movement_accumulation_process(_delta:float) -> void:
|
||||
_lateral_motion_accumulator = _lateral_motion_accumulator.lerp(character.basis.z * _max_air_velocity, _target_movement_vector.length_squared() * _delta * _air_acceleration)
|
||||
_physics_motion_accumulator = _physics_motion_accumulator.lerp(character.basis.z * _max_air_velocity, _target_movement_vector.length_squared() * _delta * _air_acceleration)
|
||||
|
||||
func _physics_movement_physics_process(_delta:float) -> void:
|
||||
_lateral_motion_accumulator = _lateral_motion_accumulator.lerp(Vector3.ZERO, _drag * _delta * (1.0 - _target_movement_vector.length_squared()))
|
||||
character.velocity = _lateral_motion_accumulator
|
||||
_physics_motion_accumulator = _physics_motion_accumulator.lerp(Vector3.ZERO, _drag * _delta * (1.0 - _target_movement_vector.length_squared()))
|
||||
body.velocity = _physics_motion_accumulator
|
||||
|
||||
func _slice_time_rotation_physics_process(_delta:float) -> void:
|
||||
character.rotate_y(-_target_movement_vector.x * _delta * 1.5)
|
||||
@@ -197,12 +198,12 @@ func _on_slice_executed() -> void:
|
||||
|
||||
func _gravity_physics_process(_delta:float) -> void:
|
||||
_gravity = clamp(_gravity + (ProjectSettings.get_setting("physics/3d/default_gravity") * _gravity_multiplier * _delta), 0.0, _terminal_velocity)
|
||||
character.velocity -= character.global_basis.y * _gravity
|
||||
body.velocity -= character.global_basis.y * _gravity
|
||||
|
||||
func _reset_all_movement() -> void:
|
||||
_target_movement_vector = Vector2.ZERO
|
||||
_current_movement_speed = 0.0
|
||||
_lateral_motion_accumulator = Vector3.ZERO
|
||||
_physics_motion_accumulator = Vector3.ZERO
|
||||
_gravity = 0.0
|
||||
|
||||
character.character_skeleton.animation_tree["parameters/walk/blend_position"] = _current_movement_speed
|
||||
|
||||
Reference in New Issue
Block a user