Fixed player double jumps not working. and added a dash
This commit is contained in:
50
Entities/Player/player_state_scripts/air_movement/dash.gd
Normal file
50
Entities/Player/player_state_scripts/air_movement/dash.gd
Normal file
@@ -0,0 +1,50 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
|
||||
const jumpGravity = player.GRAVITY
|
||||
|
||||
var dashSpeed: float = 500
|
||||
var dashTime: float = .3
|
||||
var dashDone: bool = false
|
||||
var canDash: bool = true
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
|
||||
player.velocity.y += jumpGravity * delta
|
||||
|
||||
var direction = -1 if animatedSprite2D.flip_h else 1
|
||||
|
||||
if direction:
|
||||
player.velocity.x =+ dashSpeed * direction
|
||||
|
||||
transition_states()
|
||||
|
||||
func enter() -> void:
|
||||
player.canDash = false
|
||||
dashDone = false
|
||||
animatedSprite2D.play("Fall")
|
||||
await get_tree().create_timer(dashTime).timeout
|
||||
dashDone = true
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
|
||||
if not dashDone:
|
||||
return
|
||||
|
||||
if player.is_on_floor():
|
||||
transition.emit("idle")
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("fall")
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bhyu62hovn1x3
|
||||
@@ -5,6 +5,7 @@ extends NodeState
|
||||
@export var wallCheck: ShapeCast2D
|
||||
@export var floorCheck: RayCast2D
|
||||
@export var ledgeGrabBox: CollisionShape2D
|
||||
@export var jumpState: NodeState
|
||||
|
||||
|
||||
@export_category("Fall State")
|
||||
@@ -16,15 +17,12 @@ const GRAVITY = player.GRAVITY
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.airFriction
|
||||
|
||||
var fallTimeAmount: int = 10
|
||||
var fallTime: float
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
fallTime += fallTimeAmount * delta
|
||||
#print(fallTime)
|
||||
if !player.is_on_floor():
|
||||
get_coyte_time()
|
||||
@@ -52,7 +50,6 @@ func get_coyte_time() -> void:
|
||||
|
||||
func enter() -> void:
|
||||
animatedSprite2D.play("Fall")
|
||||
fallTime = 0
|
||||
ledgeGrabBox.disabled = false
|
||||
if player.is_on_floor():
|
||||
ledgeGrabBox.disabled = true
|
||||
@@ -60,29 +57,24 @@ func enter() -> void:
|
||||
coyoteJump = true
|
||||
|
||||
func exit() -> void:
|
||||
fallTime = 0
|
||||
ledgeGrabBox.disabled = true
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
#transitioning state
|
||||
|
||||
#idle state
|
||||
if player.is_on_floor() and fallTime > 5:
|
||||
transition.emit("Land")
|
||||
|
||||
elif player.is_on_floor() and fallTime <= 5:
|
||||
if player.is_on_floor():
|
||||
transition.emit("idle")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input():
|
||||
transition.emit("jump")
|
||||
|
||||
#jump state
|
||||
if GameInputEvents.jump_input() and coyoteJump:
|
||||
transition.emit("jump")
|
||||
|
||||
if wallCheck.is_colliding() and !floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
|
||||
transition.emit("Grab")
|
||||
|
||||
if GameInputEvents.dash_input() and player.canDash:
|
||||
transition.emit("dash")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ extends NodeState
|
||||
@export var wallCheck: ShapeCast2D
|
||||
@export var floorCheck: RayCast2D
|
||||
@export var ledgeGrabBox: CollisionShape2D
|
||||
@export var fallState: NodeState
|
||||
|
||||
|
||||
const jumpGravity = player.GRAVITY
|
||||
@@ -14,13 +15,12 @@ const jumpGravity = player.GRAVITY
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.friction
|
||||
|
||||
var currentJumpCount: int
|
||||
var coyoteJump: bool
|
||||
var currentJumpCount: int = 0
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _physics_process(delta: float) -> void:
|
||||
await player.move
|
||||
if player.is_on_floor() or (player.is_on_wall() and GameInputEvents.wall_cling_input()):
|
||||
if player.is_on_floor():
|
||||
currentJumpCount = 0
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
@@ -32,19 +32,18 @@ func on_phyisics_process(delta: float) -> void:
|
||||
if player.is_on_floor():
|
||||
currentJumpCount = 0
|
||||
player.velocity.y = jumpHight
|
||||
coyoteJump = false
|
||||
fallState.coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
|
||||
if coyoteJump and currentJumpCount != maxJumpCount:
|
||||
if fallState.coyoteJump and currentJumpCount <= maxJumpCount:
|
||||
player.velocity.y = jumpHight
|
||||
coyoteJump = false
|
||||
fallState.coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
|
||||
#multi jumps
|
||||
if !player.is_on_floor() and GameInputEvents.jump_input() and currentJumpCount != maxJumpCount:
|
||||
player.velocity.y = jumpHight
|
||||
currentJumpCount += 1
|
||||
multiJump()
|
||||
|
||||
#movment shit under here
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
if direction:
|
||||
@@ -64,11 +63,13 @@ func on_phyisics_process(delta: float) -> void:
|
||||
func enter() -> void:
|
||||
ledgeGrabBox.disabled = false
|
||||
animatedSprite2D.play("Jump")
|
||||
coyoteJump = true
|
||||
if not fallState.coyoteJump:
|
||||
currentJumpCount += 1
|
||||
multiJump()
|
||||
|
||||
func exit() -> void:
|
||||
ledgeGrabBox.disabled = true
|
||||
coyoteJump = false
|
||||
fallState.coyoteJump = false
|
||||
animatedSprite2D.stop()
|
||||
|
||||
func transition_states() -> void:
|
||||
@@ -84,3 +85,12 @@ func transition_states() -> void:
|
||||
|
||||
if wallCheck.is_colliding() and not floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
|
||||
transition.emit("Grab")
|
||||
|
||||
if GameInputEvents.dash_input() and player.canDash:
|
||||
transition.emit("dash")
|
||||
|
||||
|
||||
func multiJump():
|
||||
if !player.is_on_floor() and currentJumpCount <= maxJumpCount and Input.is_action_just_pressed("move_jump"):
|
||||
player.velocity.y = jumpHight
|
||||
currentJumpCount += 1
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
extends NodeState
|
||||
|
||||
@export var player: Player
|
||||
@export var animatedSprite2D: AnimatedSprite2D
|
||||
@export var weapons: Weapons
|
||||
|
||||
|
||||
@export_category("Shoot State")
|
||||
@export var stateMachine: NodeStateMachine
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var friction = player.friction
|
||||
@onready var airFriction = player.airFriction
|
||||
var canAttack: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
animatedSprite2D.animation_looped.connect(on_loop)
|
||||
weapons.on_weapon_change.connect(on_weapon_change)
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
if player.is_on_floor():
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
|
||||
elif !player.is_on_floor():
|
||||
player.velocity.y += GRAVITY * delta
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, airFriction * delta)
|
||||
|
||||
if animatedSprite2D.frame == weapons.get_weapon_attack_frame() and canAttack:
|
||||
weapons.attack()
|
||||
canAttack = false
|
||||
|
||||
func enter() -> void:
|
||||
canAttack = true
|
||||
weapons.on_start_attack()
|
||||
play_correct_animation()
|
||||
|
||||
func exit() -> void:
|
||||
animatedSprite2D.stop()
|
||||
weapons.on_attack_end()
|
||||
|
||||
func on_loop() -> void:
|
||||
canAttack = true
|
||||
if GameInputEvents.is_first_attack_held() or GameInputEvents.is_second_attack_held():
|
||||
pass
|
||||
elif stateMachine.currentNodeState == self:
|
||||
transition.emit("idle")
|
||||
|
||||
func play_correct_animation() -> void:
|
||||
animatedSprite2D.play(weapons.get_weapon_attack_aninmation_type(), weapons.get_weapon_speed())
|
||||
|
||||
func on_weapon_change() -> void:
|
||||
canAttack = true
|
||||
play_correct_animation()
|
||||
@@ -1 +0,0 @@
|
||||
uid://b2p1m7vqxyjj7
|
||||
@@ -18,6 +18,6 @@ static func fall_input() -> bool:
|
||||
var fallInput: bool = Input.is_action_just_pressed("force_fall")
|
||||
return fallInput
|
||||
|
||||
static func wall_cling_input() -> bool:
|
||||
var wallClingInput: bool = Input.is_action_just_pressed("wall_cling")
|
||||
return wallClingInput
|
||||
static func dash_input() -> bool:
|
||||
var dashInput: bool = Input.is_action_just_pressed("dash")
|
||||
return dashInput
|
||||
|
||||
@@ -17,6 +17,7 @@ func on_phyisics_process(delta: float) -> void:
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
#player.velocity.x = move_toward(player.velocity.x, maxSpeed, 100 * delta)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
|
||||
Reference in New Issue
Block a user