Godot Version
v4.5.1-stable_win64
Question
I am trying to make a sorta like Smash Jump feature for my game and im really confused on why its not working as intended
video thingy on how its working
the detecting for the smash state is working but the jumpforce after the SJ (its tiring to type this) isnt back to its default value? im honestly confused as to why it isnt working
the jump is higher when its pressed once, and the jump is lower when held
extends CharacterBody2D
#PRIORITIES
#Being able to jump when youre just a few pixels off the ground
#vars
##Movement
@export var speed = 300
#Default Walking Speed
@export var jumpforce = 500
#Jump Height
@export var maxjump = 1
#Maximum amount of jumps
##Physics
@export var gravity = 30
#Gravity
@export var velcap = 1000
#Default Velocity Cap
@export var fallvelcap = 2000
#Velocity Cap for falling
#The velocity cap switches to fallvelcap when the player uses fast fall/smash
#otherwise the player uses the default velocity cap
var jumpnum = 1
#Available jumps
var canjump = true
#self explanatory
var cansmashjump = false
#Variable for smash jump
var xvelo = 0
#X Velocity stored as a variable
#Side to Side
var yvelo = 0
#Y Velocity stored as a variable
#Up and Down
var smashnum
#State Variables
var smashing = false
var was_on_floor = false
func _physics_process(delta):
#Print section for debugging
print(jumpnum)
if smashing == true:
print("smashing")
if cansmashjump == true:
print("Can SJ")
was_on_floor != is_on_floor()
#Gravity
if !is_on_floor():
velocity.y += gravity
if velocity.y > velcap:
velocity.y = velcap
#Coyote Timer
#checks if youre on the floor to restart the coyote timer
if (is_on_floor() == false) and canjump and $Coyote.is_stopped():
$Coyote.start()
if !was_on_floor and is_on_floor() and smashing:
$SmashJump.start()
cansmashjump = true
#checks if youre on the floor to set canjump = true
if canjump == false and is_on_floor():
jumpnum = maxjump
canjump = true
#Jump
##Replace with is_action_just_pressed for singular jump instead of continous
if Input.is_action_pressed("movejump") and canjump:
jumpnum -= 1
#var bonus = storedvel * 0.5
var final_jumpforce = jumpforce
if !cansmashjump:
final_jumpforce -= 500
cansmashjump = false
smashing = false
velocity.y = -final_jumpforce # - bonus
#storedvel = 0
#Fast Fall
if Input.is_action_just_pressed("actfastfall") and !is_on_floor():
velocity.y = fallvelcap
smashing = true
#storedvel = fallvelcap
#velocity.y = jumpforce
if Input.is_action_pressed("actslide") and velocity.x != 0:
$Sprite2D.visible = false
$CollisionShape2D.disabled = true
$Sprite2Dslide.visible = true
$CollisionShape2Dslide.disabled = false
if Input.is_action_just_released("actslide"):
$Sprite2D.visible = true
$CollisionShape2D.disabled = false
$Sprite2Dslide.visible = false
$CollisionShape2Dslide.disabled = true
#Walk
var horizontaldirection = Input.get_axis("moveleft", "moveright")
if Input.is_action_just_pressed("moveleft"):
$Sprite2Dslide.flip_v = true
$Sprite2D.flip_h = false
if Input.is_action_just_pressed("moveright"):
$Sprite2Dslide.flip_v = false
$Sprite2D.flip_h = true
velocity.x = speed * horizontaldirection
move_and_slide()
#Debug TP
if Input.is_action_just_pressed("tp"):
position.x = 566
position.y = 140
#Doesnt let you jump when coyote timer is done
func _on_coyote_timeout():
canjump = false
func _on_smash_jump_timeout():
cansmashjump = false
smashing = false
func _on_smash_jump_ready():
cansmashjump = true