Attention | Topic was automatically imported from the old Question2Answer platform. | |
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