How to make a wall climb

Godot Version

Godot 4.4 beta3

Question

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):

func on_body_entered(body):
    body.climb=true

func on_body_exited(body):
    body.climb=false

and then add this code to your players codes :

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.

good luck!

1 Like

okay, ive setup everything like you said.
the climable walls:



and i added the script.
the player also has the right script, but it is buggy.

did i do something wrong?

when this bug happenes ?

you can add this code ; mayde it can fix that.

else :
    velocity.y=0

I also added this, but it still wont work.

When does it happen?

Maybe the player actually does enter/exit the ladder multiple times when on it? Add a print_debug to the on_body_entered to check.

try it to , maybe it can fix that:

#Adds the gravity
	if not is_on_floor() and climb==false:
		velocity.y += gravity * delta

i did all that because i knew it would bug, but it still doesnt work.

yeah, this is whats actually happening.


i know i could just put only one Area2D there, but it would be annoying placing one on every climable wall. is there another way i could fix it?

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.

1 Like

oh ok.it worked! thanks!

this is because of when you enter to an area , you are exitting from another one ! and this bug happens.

good luck !

1 Like