45 lines
1.2 KiB
GDScript
45 lines
1.2 KiB
GDScript
extends PlayerState
|
|
class_name PlayerCrouched
|
|
|
|
var stand_up = false
|
|
|
|
func Enter():
|
|
character.recoil.add_recoil(Vector3(.2,0,0),5,10)
|
|
character.crouch_audio.play()
|
|
character.velocity += character.movement_input() * 20
|
|
character.standing_collision.disabled = true
|
|
|
|
func Update(delta):
|
|
#move camera down to crouched height
|
|
if character.head.position != character.CROUCHED_POS:
|
|
character.head.position = lerp(character.head.position, character.CROUCHED_POS, delta * 8)
|
|
|
|
func Physics_Update(delta):
|
|
if character.is_on_floor():
|
|
standard_movement(delta)
|
|
|
|
apply_gravity(delta)
|
|
|
|
if Input.is_action_just_pressed("crouch"):
|
|
if !character.crouch_check.is_colliding():
|
|
character.recoil.add_recoil(Vector3(-.2,.03,.03),5,10)
|
|
character.crouch_audio.play()
|
|
transition_out_of_crouch()
|
|
else:
|
|
character.recoil.add_recoil(Vector3(-.2,.03,.03),20,10)
|
|
character.hit_head.play()
|
|
|
|
if Input.is_action_just_pressed("jump"):
|
|
if !character.crouch_check.is_colliding():
|
|
character.recoil.add_recoil(Vector3(-.2,.03,.03),5,10)
|
|
standard_jump()
|
|
transition_out_of_crouch()
|
|
|
|
|
|
func transition_out_of_crouch():
|
|
character.head.position = character.STAND_POS
|
|
Transitioned.emit(self,"on foot")
|
|
|
|
func Exit():
|
|
character.standing_collision.disabled = false
|