Wall Jump teleports player off the wall

Godot Version

4.2.1 - Windows


Hey, I’m coming here because I need help with fixing my wall jump.
What’s supposed to happen is that the player should smoothly jump away from the wall in the X and Y direction when jumping, and while the Y direction works fine, the player teleports away in the X direction.

(video to show what i mean, windows game bar isnt working for me so i had to record in worse quality:

So, how do i fix this code to make it so the player smoothly jumps off the wall in the X direction and doesnt teleport off it in a janky manner? Help appreciated.
Here’s the code too:

extends CharacterBody2D

const SPEED = 105.0
const JUMP_VELOCITY = -175.0

var max_fall_speed = 155
const gravity = 450

const pushback = 500

func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta

var direction = Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED 
	velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y > max_fall_speed:
	velocity.y = max_fall_speed

if Input.is_action_pressed("ui_left"):
	$AnimatedSprite2D.flip_h = true
if Input.is_action_pressed("ui_right"):
	$AnimatedSprite2D.flip_h = false

if is_on_wall() and direction:
	max_fall_speed = 50
	max_fall_speed = 155
if is_on_wall_only() and direction and Input.is_action_just_pressed("ui_accept"):
	velocity.x = -500 * direction
	velocity.y = -120

if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY
if Input.is_action_just_released("ui_accept") and velocity.y < 0.0:
	velocity.y = 0.0


This will only set velocity.x to 500 for a single frame, and 500 is a large value so it launches the player away from the wall fast enough that it looks like it’s teleporting.

But the very next frame you’re not touching the wall anymore so is_on_wall_only() will be false and this code doesn’t run anymore, velocity.x will be just set to velocity.x = direction * SPEED that’s why the character “floats” back towards the wall immediately after.

You have to conserve the vel.x momentum somehow after wall jumping, either by lerp() -ing the velocity, or maybe disable player controls for like half a second after walljumping.

I implemented a thing that disables the controls for a very short time after walljumping, and that seems to have done the trick, thanks a bunch!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.