I can't figure out how to add wall-jumps to my 2d pixel platformer, tutorials on youtube don't help cause their setup of code is way different etc.
this is my code so far (player code)
extends KinematicBody2D
const acceleration = 512
const MAX_SPEED = 64
const friction = 0.25
const gravity = 200
const JUMP_FORCE = 128
const AIR_RESIST = 0.02
var motion = Vector2.ZERO
onready var sprite = $Sprite
onready var animationPlayer = $AnimationPlayer
func _physics_process(delta):
var x_input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if x_input != 0:
animationPlayer.play("run")
motion.x += x_input * acceleration * delta
motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
sprite.flip_h = x_input < 0
else:
animationPlayer.play("Stand")
motion.y += gravity * delta
if is_on_floor():
if x_input == 0:
motion.x = lerp(motion.x, 0, friction)
if Input.is_action_just_pressed("ui_up"):
motion.y = -JUMP_FORCE
else:
animationPlayer.play("jump")
if Input.is_action_just_released("ui_up") and motion.y < -JUMP_FORCE/2:
motion.y = -JUMP_FORCE/2
if x_input == 0:
motion.x = lerp(motion.x, 0, AIR_RESIST)
motion = move_and_slide(motion, Vector2.UP)