38 lines
1.0 KiB
GDScript
38 lines
1.0 KiB
GDScript
extends State
|
|
class_name PlayerCrouch
|
|
|
|
var crouching_cshape = preload("res://resources/player crouching cshape.tres")
|
|
var standing_cshape = preload("res://resources/player standing cshape.tres")
|
|
|
|
func get_state_name():
|
|
return str(self).split(":")[0]
|
|
|
|
func enter():
|
|
player.cshape.shape = crouching_cshape
|
|
player.cshape.position.y = -31
|
|
|
|
func exit():
|
|
player.cshape.shape = standing_cshape
|
|
player.cshape.position.y = -44
|
|
|
|
func update(delta):
|
|
|
|
var horizontal_direction = Input.get_axis("move_left", "move_right")
|
|
|
|
if player.is_on_floor():
|
|
if horizontal_direction == 0:
|
|
player.ap.play("crouch idle")
|
|
else:
|
|
Transitioned.emit(self, "PlayerCrouchwalk")
|
|
|
|
if player.head_clear() and (Input.is_action_just_released("crouch") or !Input.is_action_pressed("crouch")):
|
|
Transitioned.emit(self, "PlayerIdle")
|
|
player.stuck_under_object = false
|
|
elif !player.head_clear():
|
|
if player.stuck_under_object != true:
|
|
player.stuck_under_object = true
|
|
print("player stuck under object", player.stuck_under_object)
|
|
|
|
func physics_update(delta):
|
|
pass
|