29 lines
937 B
GDScript
29 lines
937 B
GDScript
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
|