FPS Controller
This commit is contained in:
11
demo/assets/scripts/player/states/airborne_state.gd
Normal file
11
demo/assets/scripts/player/states/airborne_state.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_airborne_state_physics_processing(_delta: float) -> void:
|
||||
if player_controller.is_on_floor():
|
||||
if player_controller.check_fall_speed():
|
||||
player_controller.camera_effects.add_fall_kick(2.0)
|
||||
|
||||
player_controller.state_chart.send_event("onGrounded")
|
||||
|
||||
player_controller.current_fall_velocity += player_controller.velocity.y
|
||||
1
demo/assets/scripts/player/states/airborne_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/airborne_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://u17omde74n8t
|
||||
10
demo/assets/scripts/player/states/base_state.gd
Normal file
10
demo/assets/scripts/player/states/base_state.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
class_name PlayerState extends Node
|
||||
|
||||
@export var debug : bool = false
|
||||
|
||||
var player_controller : PlayerController
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if %StateMachine and %StateMachine is PlayerStateMachine:
|
||||
player_controller = %StateMachine.player_controller
|
||||
1
demo/assets/scripts/player/states/base_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/base_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://yeyejbcbr1da
|
||||
12
demo/assets/scripts/player/states/crouching_state.gd
Normal file
12
demo/assets/scripts/player/states/crouching_state.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_crouching_state_physics_processing(delta: float) -> void:
|
||||
player_controller.camera.update_camera_height(delta, -1)
|
||||
|
||||
if not Input.is_action_pressed("crouch") and player_controller.is_on_floor() and not player_controller.crouch_check.is_colliding():
|
||||
player_controller.state_chart.send_event("onStanding")
|
||||
|
||||
|
||||
func _on_crouching_state_entered() -> void:
|
||||
player_controller.crouch()
|
||||
1
demo/assets/scripts/player/states/crouching_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/crouching_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bnmnicp5nu3u2
|
||||
10
demo/assets/scripts/player/states/grounded_state.gd
Normal file
10
demo/assets/scripts/player/states/grounded_state.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_grounded_state_physics_processing(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("jump") and player_controller.is_on_floor():
|
||||
player_controller.jump()
|
||||
player_controller.state_chart.send_event("onAirborne")
|
||||
|
||||
if not player_controller.is_on_floor():
|
||||
player_controller.state_chart.send_event("onAirborne")
|
||||
1
demo/assets/scripts/player/states/grounded_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/grounded_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dk8ukj487ryhj
|
||||
6
demo/assets/scripts/player/states/idle_state.gd
Normal file
6
demo/assets/scripts/player/states/idle_state.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_idle_state_processing(delta: float) -> void:
|
||||
if player_controller and player_controller._input_dir.length() > 0:
|
||||
player_controller.state_chart.send_event("onMoving")
|
||||
1
demo/assets/scripts/player/states/idle_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/idle_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d03p2engkhyjc
|
||||
6
demo/assets/scripts/player/states/moving_state.gd
Normal file
6
demo/assets/scripts/player/states/moving_state.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_moving_state_physics_processing(delta: float) -> void:
|
||||
if player_controller._input_dir.length() == 0 and player_controller.velocity.length() < 0.5:
|
||||
player_controller.state_chart.send_event("onIdle")
|
||||
1
demo/assets/scripts/player/states/moving_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/moving_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dc5dk6fyv83gt
|
||||
10
demo/assets/scripts/player/states/sprinting_state.gd
Normal file
10
demo/assets/scripts/player/states/sprinting_state.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_sprinting_state_processing(delta: float) -> void:
|
||||
if not Input.is_action_pressed("sprint"):
|
||||
player_controller.state_chart.send_event("onWalking")
|
||||
|
||||
|
||||
func _on_sprinting_state_entered() -> void:
|
||||
player_controller.sprint()
|
||||
1
demo/assets/scripts/player/states/sprinting_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/sprinting_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b40akfam2xgt
|
||||
12
demo/assets/scripts/player/states/standing_state.gd
Normal file
12
demo/assets/scripts/player/states/standing_state.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_standing_state_physics_processing(delta: float) -> void:
|
||||
player_controller.camera.update_camera_height(delta, 1)
|
||||
|
||||
if Input.is_action_pressed("crouch") and player_controller.is_on_floor():
|
||||
player_controller.state_chart.send_event("onCrouching")
|
||||
|
||||
|
||||
func _on_standing_state_entered() -> void:
|
||||
player_controller.stand()
|
||||
1
demo/assets/scripts/player/states/standing_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/standing_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1eixxgwl2exy
|
||||
10
demo/assets/scripts/player/states/walking_state.gd
Normal file
10
demo/assets/scripts/player/states/walking_state.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends PlayerState
|
||||
|
||||
|
||||
func _on_walking_state_processing(delta: float) -> void:
|
||||
if Input.is_action_pressed("sprint"):
|
||||
player_controller.state_chart.send_event("onSprinting")
|
||||
|
||||
|
||||
func _on_walking_state_entered() -> void:
|
||||
player_controller.walk()
|
||||
1
demo/assets/scripts/player/states/walking_state.gd.uid
Normal file
1
demo/assets/scripts/player/states/walking_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bstd2nopn6ur
|
||||
Reference in New Issue
Block a user