This repository has been archived on 2026-05-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
instructions-clear/scripts/states/run.gd
T
2025-02-02 01:08:44 +09:00

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