refactor to state machine
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
extends State
|
||||
|
||||
func process_physics(delta: float) -> State:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
var input_direction = %Input.direction
|
||||
if input_direction.length() < 0.05:
|
||||
return %Idle
|
||||
|
||||
var move_direction = Vector3(input_direction.x, 0, input_direction.y)
|
||||
var target_velocity = Vector3(move_direction.x * subject.run_speed, subject.velocity.y, move_direction.z * subject.run_speed)
|
||||
subject.velocity = subject.velocity.move_toward(target_velocity, subject.acceleration * delta)
|
||||
subject.velocity += Main.gravity_velocity
|
||||
subject.move_and_slide()
|
||||
|
||||
if move_direction.length() >= 0.1:
|
||||
subject.last_direction = move_direction
|
||||
var target_angle := Vector3.FORWARD.signed_angle_to(subject.last_direction, Vector3.UP)
|
||||
subject.skin.global_rotation.y = lerp_angle(subject.skin.rotation.y, target_angle, subject.rotation_speed * delta)
|
||||
|
||||
if %Input.walking:
|
||||
return %Walk
|
||||
|
||||
if not subject.is_on_floor():
|
||||
return %Fall
|
||||
|
||||
return
|
||||
Reference in New Issue
Block a user