Godot Version
4.2.1
Question
How do I fix this script to make it allow me to wall jump?
I’m relatively new to Godot and I want to make a platformer… a test one at last and I want to make the character do a wall jump. I followed one tutorial and the Godot Docs but got nowhere. I even tried Reddit. So, here’s the script for it. Help will be much appreciated!
extends CharacterBody2D
@export var speed = 400.0
@export var jump_speed = -1400.0
@export var wall_jump_push = 100
var gravity = 120
var wall_slide_gravity = 100
var is_wall_sliding = false
func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision:
Input.get_axis("ui_up", "ui_down")
var input_direction = Input.get_axis("ui_left", "ui_right")
velocity.x = input_direction * speed
move_and_slide()
jump()
wall_slide(delta)
func jump():
velocity.y += gravity
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_speed
func wall_jump():
if is_on_wall() and Input.is_action_pressed("jump"):
gravity = 75.0
else:
jump()
func wall_slide(delta):
if is_on_wall() and !is_on_floor():
if Input.is_action_pressed("ui_left") or Input.is_action_pressed("ui_right"):
is_wall_sliding = true
else:
is_wall_sliding = false
else:
is_wall_sliding = false
if is_wall_sliding:
velocity.y += (wall_slide_gravity * delta)
velocity.y = min(velocity.y, wall_slide_gravity)