#wall jump wont work

1 messages · Page 1 of 1 (latest)

dry apex
#

func jump(delta):
velocity.y = JUMP_VELOCITY
func player_movement(delta: float) -> void:
if not is_on_floor():
velocity.y += gravity * delta
if is_on_wall() and Input.is_key_pressed(KEY_W):
canMoveX = false

        jump(delta)
        velocity.x = - velocity.x*2
        position.x += -direction*4
    else:
        canMoveX = true
        

if Input.is_key_pressed(KEY_W) and is_on_floor():
    jump(delta)


if Input.is_key_pressed(KEY_A):
        
        
    direction = -1
    velocity.x = -SPEED 
elif Input.is_key_pressed(KEY_D):
    direction = 1
    
    velocity.x = SPEED 
else:
    if canMoveX == true:
        velocity.x = 0

im trying to add a wall jump
but it wont launch you in the other direction

cedar surge
#

You'll want to wrap your code like this:

#

Which will look like this:

code goes here
#

I don't see the wall normal anywhere in this code. For basic wall jumping you typically get the wall normal while touching a wall and then use that as the direction in your jump vector

#

CharacterBody makes it easy since it has get_wall_normal()

#

So it would look something like this:

if is_on_wall():
  var wall_normal: Vector2 = get_wall_normal()
  var wall_jump_impulse: Vector2 = (wall_normal * up_direction * wall_jump_speed)
  if Input.is_action_just_pressed("jump"):
    velocity = wall_jump_impulse
dry apex
cedar surge
#

It's a built-in property of the CharacterBody class. By default is it equal to Vector2.UP