41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
extends State
|
|
|
|
@export var SPEED: float = 2.5
|
|
@export var JUMP_VELOCITY: float = 4.5
|
|
@export var player: Player
|
|
|
|
func enter() -> void:
|
|
pass
|
|
|
|
func exit() -> void:
|
|
pass
|
|
|
|
func physics_update(_delta: float) -> void:
|
|
if not is_multiplayer_authority():
|
|
return
|
|
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
|
player.velocity.y = JUMP_VELOCITY
|
|
transition.emit("Fall")
|
|
return
|
|
|
|
if not player.is_on_floor():
|
|
transition.emit("Fall")
|
|
return
|
|
|
|
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
|
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
if direction:
|
|
player.velocity.x = direction.x * SPEED
|
|
player.velocity.z = direction.z * SPEED
|
|
else:
|
|
player.velocity.x = move_toward(player.velocity.x, 0, SPEED)
|
|
player.velocity.z = move_toward(player.velocity.z, 0, SPEED)
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if not is_multiplayer_authority():
|
|
return
|
|
if event.is_action_released("plr_walk"):
|
|
transition.emit("Stand")
|
|
|
|
if event.is_action_pressed("plr_crouch"):
|
|
transition.emit("Crouch")
|