Wall slide and Wall jump mechanic

Godot Version

#Jump
if Input.is_action_just_pressed(“ui_jump”) and is_on_floor():
velocity.y += jump
anim.play(“Jump”)
floatUpTimer = 0

#Wall Slide
if is_on_wall() and not is_on_floor():
if Input.is_action_pressed(“ui_left”) or Input.is_action_pressed(“ui_right”):
is_wall_sliding = true
else:
is_wall_sliding = false
else:
is_wall_sliding = false
if is_wall_sliding:
velocity.y += (WallSlideGravity * delta)
velocity.y = min(velocity.y, WallSlideGravity)
anim.play(“Slide”)
wallJumpTimer += delta

#Wall Jump
if is_wall_sliding and Input.is_action_pressed(“ui_jump”) and wallJumpTimer >
velocity.y += jump
if Input.is_action_pressed(“ui_left”):
velocity.x = WallJumpPushBack
if Input.is_action_pressed(“ui_right”):
velocity.x = -WallJumpPushBack
anim.play(“Jump”)
wallJumpTimer = 0

#Floating up after the initial jump.
if Input.is_action_pressed(“ui_jump”) and floatUpTimer < MaxFloatTime:
velocity.y = floatUpVelocity
floatUpTimer += delta
anim.play(“Jump”)

#Prevent floating infinitely.
else:
floatUpTimer = MaxFloatTime

Question

so i have this code and it works well for me but i wanted to add something to the wall jump, where lets say i have 2 walls, the left and the right wall. If i jump off the right wall i want there to be a 1 sec timer before your next jump, which i have so you cant just climb jumping off the same wall. However, i wanted to make it so that if you jump from the right wall to the left then the timer is null. Idk i cant get my mind around the code to add, please help and if my code looks horrible im sorry i just started learning coding yesterday

1 Like

The way I will do this is to keep track of the player direction while still keeping track of the 1sec timer. The logic will be something like this, if the player direction is the same when the last wall just was made and 1sec has not elapsed, don’t jump. But if the player has changed direction after the last jump, wall jump even if 1sec has not elapsed.

If I understood this correctly, then the way to do this is by doing something like this:

if is_on_wall_only() and direction and Input.is_action_just_pressed(“jump”):
velocity.x = -pushback * direction
velocity.y = pushbackY
directionTrue = false
$wallTimer.start()

  • Add a true/false variable for confirming if you are allowed to control your character direction (X axis) (true by default)
  • Add a timer, set it for about 0.15s (1s is too much)
  • Use a signal to link the timer to the code and put pass under the timeout signal for now
  • Add the above if condition to a new wallJump() function or physics_process()
  • in the if, use velocity on Y and X with the assigned variables for the walljump pushbacks
  • in the if, set the allowing-direction variable to false
  • in the if, start the timer via $(timername).start()
  • fill in the timeout function with “directionTrue = true”

– If you made this code in a new function, call the function in physics_process, otherwise ignore this if you put this code in physics_process

This is how I’m doing it in my game, so I hope this helps you! If it doesn’t, let me know and I’ll see if I can assist further!