I'm trying to implement a wall jump in my platformer. When testing, I noticed a strange issue: the character would wall jump, then stop movement on the x-axis - horizontal movement that is.
Took me a few days to figure out the issue: when the variable which checked if the wall jump has occurred nullified, the code would check for horizontal movement, and as no movement buttons are pressed it would reset velocity to 0.
Here's the relevant code:
extends KinematicBody2D
const Gravity = Vector2(0, 400.0)
const WalkSpeed = 150
const WallJumpVelocity = Vector2(150, -100)
onready var WallJumpTimer = get_node("WallJumpTimer")
var JumpVelocity = -250.0
var WallJump = false
var Jumped = false
var velocity = Vector2()
signal WallJumpSignal
func get_input():
if WallJump == false:
if Input.is_action_pressed("Left"):
velocity.x = -WalkSpeed
get_node("AnimatedSprite").set_flip_h(true)
elif Input.is_action_pressed("Right"):
velocity.x = WalkSpeed
get_node("AnimatedSprite").set_flip_h(false)
else:
velocity.x = 0
if is_on_wall():
emit_signal("WallJumpSignal")
if is_on_floor():
WallJump = false
func _physics_process(delta):
get_input()
velocity.y += delta * Gravity.y
velocity = move_and_slide(velocity, Vector2(0, -1))
func _on_Character_WallJumpSignal():
var WallDirection = get_which_wall_collided()
if Input.is_action_just_pressed("Up"):
WallJump = true
#Jumped = true
WallJumpTimer.start()
if WallDirection == "left":
velocity = WallJumpVelocity
get_node("AnimatedSprite").set_flip_h(false)
if WallDirection == "right":
velocity.y = WallJumpVelocity.y
velocity.x = -WallJumpVelocity.x
get_node("AnimatedSprite").set_flip_h(true)
func _on_WallJumpTimer_timeout():
WallJump = false
Sorry, my code is a mess. I'm a relatively new developer.
Can anyone please help me with this issue? Been trying to solve it for a few days now.