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
+10 -7
View File
@@ -11,13 +11,13 @@ signal move
#State Vars #State Vars
const GRAVITY: int = 700 const GRAVITY: int = 700
@export var speed: float = 1000 @export var speed: float = 1300
@export var maxSpeed: float = 175 @export var maxSpeed: float = 300
@export var friction: int = 1000 @export var friction: int = 1200
@export var airFriction: int = 250 @export var airFriction: int = 250
@export var jumpHight: float = -275 @export var jumpHight: float = -275
@export var maxJumpCount: int = 1 @export var maxJumpCount: int = 2
@export var ammo: int = 3 var canDash: bool = true
var deathEffect: PackedScene = preload("uid://dm4oirxl6bpnn") var deathEffect: PackedScene = preload("uid://dm4oirxl6bpnn")
var camreaCenterPosition: Vector2 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 #emits move purly for jump state cause that is dependent on exact move and slide in the code
move.emit() move.emit()
if is_on_floor():
canDash = true
#kills the player when they get too low #kills the player when they get too low
if global_position.y > 200: #if global_position.y > 200:
player_death() #player_death()
#sets the players pos to the spawn pos so the player statrs on the correct door to the level #sets the players pos to the spawn pos so the player statrs on the correct door to the level
func on_spawn(spawnPosition: Vector2): func on_spawn(spawnPosition: Vector2):
+13 -11
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="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://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"] [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://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://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://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://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"] [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"]] [node name="Player" type="CharacterBody2D" groups=["Player"]]
collision_layer = 2 collision_layer = 2
script = ExtResource("1_8soms") script = ExtResource("1_8soms")
speed = null
maxSpeed = null
friction = null
airFriction = null
jumpHight = null
maxJumpCount = null
ammo = null
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_rqcxa") material = SubResource("ShaderMaterial_rqcxa")
@@ -1090,21 +1084,24 @@ script = ExtResource("15_rqcxa")
player = NodePath("../..") player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D") 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") script = ExtResource("14_kjljb")
player = NodePath("../..") player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D") animatedSprite2D = NodePath("../../AnimatedSprite2D")
wallCheck = NodePath("../../HitBoxes/WallCheck") wallCheck = NodePath("../../HitBoxes/WallCheck")
floorCheck = NodePath("../../HitBoxes/FloorCheck") floorCheck = NodePath("../../HitBoxes/FloorCheck")
ledgeGrabBox = NodePath("../../LedgeGrab") 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") script = ExtResource("14_3ep63")
player = NodePath("../..") player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D") animatedSprite2D = NodePath("../../AnimatedSprite2D")
wallCheck = NodePath("../../HitBoxes/WallCheck") wallCheck = NodePath("../../HitBoxes/WallCheck")
floorCheck = NodePath("../../HitBoxes/FloorCheck") floorCheck = NodePath("../../HitBoxes/FloorCheck")
ledgeGrabBox = NodePath("../../LedgeGrab") ledgeGrabBox = NodePath("../../LedgeGrab")
jumpState = NodePath("../Jump")
coyoteTime = 0.3
[node name="Land" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D")] [node name="Land" type="Node" parent="StateMachine" node_paths=PackedStringArray("player", "animatedSprite2D")]
script = ExtResource("24_bp242") script = ExtResource("24_bp242")
@@ -1137,6 +1134,11 @@ player = NodePath("../..")
animatedSprite2D = NodePath("../../AnimatedSprite2D") animatedSprite2D = NodePath("../../AnimatedSprite2D")
collisionShapeMove = NodePath("../../HitBoxes/CollisionShapeMove") 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="."] [node name="HitAnimationPlayer" type="AnimationPlayer" parent="."]
libraries = { libraries = {
&"": SubResource("AnimationLibrary_usp30") &"": SubResource("AnimationLibrary_usp30")
@@ -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 wallCheck: ShapeCast2D
@export var floorCheck: RayCast2D @export var floorCheck: RayCast2D
@export var ledgeGrabBox: CollisionShape2D @export var ledgeGrabBox: CollisionShape2D
@export var jumpState: NodeState
@export_category("Fall State") @export_category("Fall State")
@@ -16,15 +17,12 @@ const GRAVITY = player.GRAVITY
@onready var maxSpeed = player.maxSpeed @onready var maxSpeed = player.maxSpeed
@onready var friction = player.airFriction @onready var friction = player.airFriction
var fallTimeAmount: int = 10
var fallTime: float
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
func on_process(delta: float) -> void: func on_process(delta: float) -> void:
pass pass
func on_phyisics_process(delta: float) -> void: func on_phyisics_process(delta: float) -> void:
fallTime += fallTimeAmount * delta
#print(fallTime) #print(fallTime)
if !player.is_on_floor(): if !player.is_on_floor():
get_coyte_time() get_coyte_time()
@@ -52,7 +50,6 @@ func get_coyte_time() -> void:
func enter() -> void: func enter() -> void:
animatedSprite2D.play("Fall") animatedSprite2D.play("Fall")
fallTime = 0
ledgeGrabBox.disabled = false ledgeGrabBox.disabled = false
if player.is_on_floor(): if player.is_on_floor():
ledgeGrabBox.disabled = true ledgeGrabBox.disabled = true
@@ -60,29 +57,24 @@ func enter() -> void:
coyoteJump = true coyoteJump = true
func exit() -> void: func exit() -> void:
fallTime = 0
ledgeGrabBox.disabled = true ledgeGrabBox.disabled = true
animatedSprite2D.stop() animatedSprite2D.stop()
func transition_states() -> void: func transition_states() -> void:
#transitioning state #transitioning state
#idle state if player.is_on_floor():
if player.is_on_floor() and fallTime > 5:
transition.emit("Land")
elif player.is_on_floor() and fallTime <= 5:
transition.emit("idle") transition.emit("idle")
#jump state #jump state
if GameInputEvents.jump_input(): if GameInputEvents.jump_input():
transition.emit("jump") 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(): if wallCheck.is_colliding() and !floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
transition.emit("Grab") 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 wallCheck: ShapeCast2D
@export var floorCheck: RayCast2D @export var floorCheck: RayCast2D
@export var ledgeGrabBox: CollisionShape2D @export var ledgeGrabBox: CollisionShape2D
@export var fallState: NodeState
const jumpGravity = player.GRAVITY const jumpGravity = player.GRAVITY
@@ -14,13 +15,12 @@ const jumpGravity = player.GRAVITY
@onready var maxSpeed = player.maxSpeed @onready var maxSpeed = player.maxSpeed
@onready var friction = player.friction @onready var friction = player.friction
var currentJumpCount: int var currentJumpCount: int = 0
var coyoteJump: bool
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
await player.move 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 currentJumpCount = 0
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
@@ -32,19 +32,18 @@ func on_phyisics_process(delta: float) -> void:
if player.is_on_floor(): if player.is_on_floor():
currentJumpCount = 0 currentJumpCount = 0
player.velocity.y = jumpHight player.velocity.y = jumpHight
coyoteJump = false fallState.coyoteJump = false
currentJumpCount += 1 currentJumpCount += 1
if coyoteJump and currentJumpCount != maxJumpCount: if fallState.coyoteJump and currentJumpCount <= maxJumpCount:
player.velocity.y = jumpHight player.velocity.y = jumpHight
coyoteJump = false fallState.coyoteJump = false
currentJumpCount += 1 currentJumpCount += 1
#multi jumps #multi jumps
if !player.is_on_floor() and GameInputEvents.jump_input() and currentJumpCount != maxJumpCount: multiJump()
player.velocity.y = jumpHight
currentJumpCount += 1
#movment shit under here
var direction: float = GameInputEvents.movement_input() var direction: float = GameInputEvents.movement_input()
if direction: if direction:
@@ -64,11 +63,13 @@ func on_phyisics_process(delta: float) -> void:
func enter() -> void: func enter() -> void:
ledgeGrabBox.disabled = false ledgeGrabBox.disabled = false
animatedSprite2D.play("Jump") animatedSprite2D.play("Jump")
coyoteJump = true if not fallState.coyoteJump:
currentJumpCount += 1
multiJump()
func exit() -> void: func exit() -> void:
ledgeGrabBox.disabled = true ledgeGrabBox.disabled = true
coyoteJump = false fallState.coyoteJump = false
animatedSprite2D.stop() animatedSprite2D.stop()
func transition_states() -> void: 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(): if wallCheck.is_colliding() and not floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
transition.emit("Grab") 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") var fallInput: bool = Input.is_action_just_pressed("force_fall")
return fallInput return fallInput
static func wall_cling_input() -> bool: static func dash_input() -> bool:
var wallClingInput: bool = Input.is_action_just_pressed("wall_cling") var dashInput: bool = Input.is_action_just_pressed("dash")
return wallClingInput return dashInput
@@ -17,6 +17,7 @@ func on_phyisics_process(delta: float) -> void:
if direction: if direction:
player.velocity.x += direction * speed * delta player.velocity.x += direction * speed * delta
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed) player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
#player.velocity.x = move_toward(player.velocity.x, maxSpeed, 100 * delta)
if direction != 0: if direction != 0:
animatedSprite2D.flip_h = false if direction > 0 else true animatedSprite2D.flip_h = false if direction > 0 else true
File diff suppressed because one or more lines are too long
+21 -2
View File
@@ -11,7 +11,8 @@ config_version=5
[application] [application]
config/name="TSA" config/name="TSA"
config/features=PackedStringArray("4.5", "C#", "Forward Plus") run/main_scene="uid://dtkg88hfvln2d"
config/features=PackedStringArray("4.5", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload] [autoload]
@@ -24,11 +25,21 @@ window/size/viewport_width=640
window/size/viewport_height=360 window/size/viewport_height=360
window/size/window_width_override=1280 window/size/window_width_override=1280
window/size/window_height_override=720 window/size/window_height_override=720
window/stretch/mode="viewport"
[dotnet] [dotnet]
project/assembly_name="TSA" project/assembly_name="TSA"
[file_customization]
folder_colors={
"res://Entities/": "orange",
"res://Envoroment/": "yellow",
"res://auto_loads/": "red",
"res://utilities/": "green"
}
[input] [input]
move_left={ move_left={
@@ -56,8 +67,16 @@ force_fall={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
] ]
} }
wall_cling={ dash={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":74,"key_label":0,"unicode":106,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":74,"key_label":0,"unicode":106,"location":0,"echo":false,"script":null)
] ]
} }
[physics]
common/physics_interpolation=true
[rendering]
textures/canvas_textures/default_texture_filter=0