Wall Jump Help

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By djmick

I’m making a platform right now and I’m trying to implement a wall jump. I would like it so that when you are on the wall, you move 45 degrees up and in the opposite direction. I assume you would just set that movement and then disable the controls for a moment, but I do not know how to do that. Any ideas? Here is my platform code:

func _physics_process(delta):

velocity.y += gravity
velocity.x = 0
wall_jump.x = 0
wall_jump.y = 0
if Input.is_action_pressed("move_left"):
	velocity.x = -speed
	sprite.flip_h = true
	ray.rotation_degrees = 90
if Input.is_action_pressed("move_right"):
	velocity.x = speed
	sprite.flip_h = false
	ray.rotation_degrees = 270
if Input.is_action_pressed("jump") && is_on_floor():
	velocity.y = jump_force
if Input.is_action_just_released("jump") && velocity.y < 0:
	velocity.y *= 0.5
if Input.is_action_just_pressed("jump") && ray.is_colliding() && sprite.flip_h == false:
	velocity.y = jump_force
	velocity.x = -jump_force
if Input.is_action_just_pressed("jump") && ray.is_colliding() && sprite.flip_h == false:
	velocity.y = jump_force
	velocity.x = jump_force
if is_on_floor() && velocity.y > 5:
	velocity.y = 5
move_and_slide(velocity, Vector2(0,-1))

Have you looked at the function is_on_wall()? Maybe you could check that, and check whether the player isn’t on the floor. Then you could code the player to jump off the wall.

Ertain | 2020-06-16 23:27

:bust_in_silhouette: Reply From: Chafmere

Hi There,

I have recently tackled this issue. What I have done is create a variable like “justWallJumped” and set to false by default. Then wrapped my left and right movement in an if statement that checks if justWallJumped is true. If true then you cannot use the directional controls. Then when a wall jump is executed the variable is set to true and a timer called wall_jump_cool_down is started, this last for a second or two. When the timer ends a signal is produced and sets “justWallJumped” back to false allowing the player to input movement again. The time on timer will depend on how long your character spends in the air. I’ve set mine to coincide with the peak of the ark.

This implementation prevents them from being able to scale walls without another object to “grab” on to on the opposite side. They also can’t tell that all movement is disabled as the direction kicks back in at a moment when, if they were pushing away from the wall, the character would continue to do that.

Thank you very much! I wasn’t really expecting an answer to be honest, let alone a good one, but this helped perfectly. Thank you!

djmick | 2020-06-17 21:23