Godot Version
Question
Hey y’all i’m trying to implement a wall jump mechanic on my game, but after implementing the code i get these weird little hops. What do i need to fix to get proper wall jumps?
This is all the code on my player
extends CharacterBody2D
# character ability variables to enable or disable them
var jump_get : bool = true
var wall_slide : bool = true
var wall_jump_get : bool = true
#number of times the player can jump
var jump_count : int = 0
var max_jumps : int = 1
var do_wall_jump : bool = false
const wall_sliding_speed = 1200
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
# Add the gravity.
if is_on_wall_only() and wall_slide == true : velocity.y = wall_sliding_speed * delta
elif not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("ui_accept"):
if is_on_wall_only() and wall_jump_get == true:
velocity.y = JUMP_VELOCITY
velocity.x = -direction * SPEED
do_wall_jump = true
$wall_jump_timer.start()
elif is_on_floor() and jump_get == true and jump_count < max_jumps:
velocity.y = JUMP_VELOCITY
jump_count += 1
if direction && not do_wall_jump: velocity.x = direction * SPEED
elif not do_wall_jump: velocity.x = move_toward(velocity.x, 0, SPEED)
if is_on_floor():
jump_count = 0
# Handle jump.
move_and_slide()
func _on_wall_jump_timer_timeout():
do_wall_jump = false