crouching, walking and jumping
This commit is contained in:
parent
58ccdbce0e
commit
f312e0a4a6
9 changed files with 71 additions and 60 deletions
|
|
@ -3,9 +3,9 @@ extends State
|
|||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float = 2.0
|
||||
@export var deceleration: float = 200.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var weapon_system: WeaponSystem
|
||||
@export var audio: MultiplayerAudio3D
|
||||
@export var step_delay: float
|
||||
|
|
@ -14,18 +14,19 @@ extends State
|
|||
var step_time: float
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
player_input.jumped.connect(on_jumped)
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_begin.connect(begin_walk)
|
||||
|
||||
func exit() -> void:
|
||||
player_input.jumped.disconnect(on_jumped)
|
||||
player_input.crouch_begin.disconnect(begin_crouch)
|
||||
player_input.walk_begin.disconnect(begin_walk)
|
||||
step_time = 0
|
||||
|
||||
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 * sign(weapon_system.get_speed_modifier())
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -38,9 +39,13 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
transition.emit("Crouch")
|
||||
|
||||
if event.is_action_pressed("plr_walk"):
|
||||
transition.emit("Walk")
|
||||
func on_jumped() -> void:
|
||||
if player.is_on_floor():
|
||||
player_movement.jump()
|
||||
transition.emit("Fall")
|
||||
|
||||
func begin_walk() -> void:
|
||||
transition.emit("Walk")
|
||||
|
||||
func begin_crouch() -> void:
|
||||
transition.emit("Crouch")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue