Fixed player double jumps not working. and added a dash

This commit is contained in:
2026-02-12 06:56:01 -05:00
parent 83a4a8f374
commit 5518f3ce79
12 changed files with 129 additions and 108 deletions

View 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")

View File

@@ -0,0 +1 @@
uid://bhyu62hovn1x3

View File

@@ -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")

View File

@@ -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