Godot Version
4.2.1 - Windows
Question
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
$AnimatedSprite2D.play("Run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
$AnimatedSprite2D.play("Idle")
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
else:
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
move_and_slide()