Hello! I am making a platformer game, and i want to make a wall climb. its like a wall slide, but you can control if youre going down or up, and i want to have a wall jump in it to. i was testing around, but nothing worked. can someone help?
here’s the full player controller:
extends CharacterBody2D
@export var max_speed = 300
@export var max_run = 500
@export var buildup_speed = 30
@export var gravity = 1800
@export var jump_force = 1200
@onready var sprite: AnimatedSprite2D = $Sprite
@onready var slide: CPUParticles2D = $Slide
@onready var ray_left: RayCast2D = $left
@onready var ray_right: RayCast2D = $right
@export var wall_jump_pushback = -320.0
var is_running = false
var jreleased = false
func _physics_process(delta: float) -> void:
#Adds the gravity
if not is_on_floor():
velocity.y += gravity * delta
#Handles the jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
jreleased = false
velocity.y = -jump_force
if Input.is_action_just_released("jump") and jreleased == false:
jreleased = true
velocity.y *= 0.65
#Handles the Running
if Input.is_action_pressed("run"):
is_running = true
else:
is_running = false
#Handles the Input
var input = Input.get_axis("left", "right")
if input:
if is_running == true:
velocity.x += input * buildup_speed
if velocity.x > max_run:
velocity.x = max_run
elif velocity.x < -max_run:
velocity.x = -max_run
else:
velocity.x += input * buildup_speed
if velocity.x > max_speed:
velocity.x = max_speed
elif velocity.x < -max_speed:
velocity.x = -max_speed
if input == 1:
sprite.flip_h = false
elif input == -1:
sprite.flip_h = true
else:
if is_on_floor():
velocity.x = move_toward(velocity.x, 0, buildup_speed)
else:
velocity.x = move_toward(velocity.x, 0, buildup_speed/5)
#Handles Animations
if not is_on_floor():
slide.emitting = false
if velocity.y < 0:
sprite.animation = "jump"
else:
sprite.animation = "fall"
else:
if (input == 1 and velocity.x < 0) or (input == -1 and velocity.x > 0):
slide.emitting = true
sprite.animation = "slide"
elif (velocity.x > 1 || velocity.x < -1):
slide.emitting = false
if velocity.x > 300 || velocity.x<-300:
sprite.animation = "run"
else:
sprite.animation = "walk"
else:
sprite.animation = "idle"
move_and_slide()
at first attach this code to the ladder or wall climber . and then , add an area to the ladder as a child node. and use body entered/exited signal (you dont have to write name of codes. by choosing its signal , it will write by it self):
var climb : bool
func physics_process(delta):
if climb==true :
if Input.is_action_pressed("up"):
velocity.y=-30 #for example 30
elif Input.is_action_pressed("down"):
velocity.y=30
and jumping is like normal jumping , just you should use is_on_wall()
instead of is_on_floor() to wall jumping.
you can enable “visible colision shapes” on debug tab and check the collisions. and also you can check monitoring of the area 2D to find the origin of bug using print().
ok ok now I try that and made this ladder .
i understood how to fix it.
this must have a one area . just one of ladders should have an area and others must to be just picture without area. you can increase vertical scale of this area 2D for having a big ladder.