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

@@ -11,13 +11,13 @@ signal move
#State Vars
const GRAVITY: int = 700
@export var speed: float = 1000
@export var maxSpeed: float = 175
@export var friction: int = 1000
@export var speed: float = 1300
@export var maxSpeed: float = 300
@export var friction: int = 1200
@export var airFriction: int = 250
@export var jumpHight: float = -275
@export var maxJumpCount: int = 1
@export var ammo: int = 3
@export var maxJumpCount: int = 2
var canDash: bool = true
var deathEffect: PackedScene = preload("uid://dm4oirxl6bpnn")
var camreaCenterPosition: Vector2
@@ -36,9 +36,12 @@ func _physics_process(delta: float) -> void:
#emits move purly for jump state cause that is dependent on exact move and slide in the code
move.emit()
if is_on_floor():
canDash = true
#kills the player when they get too low
if global_position.y > 200:
player_death()
#if global_position.y > 200:
#player_death()
#sets the players pos to the spawn pos so the player statrs on the correct door to the level
func on_spawn(spawnPosition: Vector2):

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=126 format=3 uid="uid://ca7jd0ttc0v67"]
[gd_scene load_steps=127 format=3 uid="uid://ca7jd0ttc0v67"]
[ext_resource type="Script" uid="uid://0oxneml3esdx" path="res://entities/player/player.gd" id="1_8soms"]
[ext_resource type="Script" uid="uid://0oxneml3esdx" path="res://Entities/Player/player.gd" id="1_8soms"]
[ext_resource type="Shader" uid="uid://cqjsw6d71kkd2" path="res://Entities/Player/player_hit_flash_shader.tres" id="2_3ep63"]
[ext_resource type="Texture2D" uid="uid://dravykrek6bsu" path="res://Entities/Player/player_art/the_dude/climbing/player wall slide 48x48.png" id="3_epc1c"]
[ext_resource type="Texture2D" uid="uid://blgt31uqia0oh" path="res://Entities/Player/player_art/the_dude/movement/Player Idle 48x48.png" id="3_gh012"]
@@ -22,6 +22,7 @@
[ext_resource type="Script" uid="uid://d3t3fweggs161" path="res://Entities/Player/player_state_scripts/ground_movement/grab_state.gd" id="23_kjljb"]
[ext_resource type="Script" uid="uid://iu5jv2o1im70" path="res://Entities/Player/player_state_scripts/air_movement/land_state.gd" id="24_bp242"]
[ext_resource type="Script" uid="uid://cmtajhnx8xaqt" path="res://Entities/Player/player_state_scripts/ground_movement/crouch_idle.gd" id="24_brh81"]
[ext_resource type="Script" uid="uid://bhyu62hovn1x3" path="res://Entities/Player/player_state_scripts/air_movement/dash.gd" id="25_01ng6"]
[ext_resource type="Script" uid="uid://cywssm5t3d5uv" path="res://Entities/Player/player_state_scripts/ground_movement/slide_state.gd" id="26_bp242"]
[ext_resource type="Script" uid="uid://c2lag80wot5k" path="res://Entities/Player/player_state_scripts/ground_movement/crouch_walk_state.gd" id="28_y6drd"]
@@ -1007,13 +1008,6 @@ _data = {
[node name="Player" type="CharacterBody2D" groups=["Player"]]
collision_layer = 2
script = ExtResource("1_8soms")
speed = null
maxSpeed = null
friction = null
airFriction = null
jumpHight = null
maxJumpCount = null
ammo = null
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_rqcxa")
@@ -1090,21 +1084,24 @@ script = ExtResource("15_rqcxa")
player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D")
[node name="Jump" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D", "wallCheck", "floorCheck", "ledgeGrabBox")]
[node name="Jump" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D", "wallCheck", "floorCheck", "ledgeGrabBox", "fallState")]
script = ExtResource("14_kjljb")
player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D")
wallCheck = NodePath("../../HitBoxes/WallCheck")
floorCheck = NodePath("../../HitBoxes/FloorCheck")
ledgeGrabBox = NodePath("../../LedgeGrab")
fallState = NodePath("../Fall")
[node name="Fall" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D", "wallCheck", "floorCheck", "ledgeGrabBox")]
[node name="Fall" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D", "wallCheck", "floorCheck", "ledgeGrabBox", "jumpState")]
script = ExtResource("14_3ep63")
player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D")
wallCheck = NodePath("../../HitBoxes/WallCheck")
floorCheck = NodePath("../../HitBoxes/FloorCheck")
ledgeGrabBox = NodePath("../../LedgeGrab")
jumpState = NodePath("../Jump")
coyoteTime = 0.3
[node name="Land" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D")]
script = ExtResource("24_bp242")
@@ -1137,6 +1134,11 @@ player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D")
collisionShapeMove = NodePath("../../HitBoxes/CollisionShapeMove")
[node name="Dash" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D")]
script = ExtResource("25_01ng6")
player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D")
[node name="HitAnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_usp30")

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

View File

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

View File

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

View File

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

View File

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