Trying To Make A wall run that sticks a character to a wall

Godot Version

4.4

Question

Hello I am trying to make a wall run and wall run jumpsuch as the game Rayman legends/ Orgins I think it could be a problem with my gravity formula which looks like this

@export var jump_height : float = 100.0
@export var jump_time_to_peak : float = 0.9
@export var jump_time_to_descent : float = 0.25


@onready var jump_velocity : float = ((2.0 * jump_height) / jump_time_to_peak) * -1.0
@onready var jump_gravity : float = ((-2.5 * jump_height) / (jump_time_to_peak * jump_time_to_peak)) * -1.0
@onready var fall_gravity : float =((-2.5 * jump_height) / (jump_time_to_descent * jump_time_to_descent)) * -1.0


func gravity() -> float:
	return jump_gravity if velocity.y < 0.0 else fall_gravity


func handle_jump():
	if is_on_floor():
		velocity.y = jump_velocity
		is_jumping = true

And I am checking if im on a slope and rotating the character with

var offset: float = deg_to_rad(0)
var fall_off_wall = false #makes the characte fall off the wall
var control_lock = false #disables the inputs of left and right
var slope_steep := 0.0 #checks steepness of slopes 
var slope_factor := 0.0
var grounded := false #checks if is on ground
var rot := 0.0 #Rotation of sprites and collisions


		if is_on_floor():
			
			slope_steep = get_floor_normal().angle() + (PI / 2)
			
			slope_factor = get_floor_normal().x
			
		else:
			slope_factor = 0

		$OrenCollisions.rotation = rot
		
		$PlayerSprites.rotation = lerp_angle($PlayerSprites.rotation, rot, 0.25)
		
		if is_on_floor(): #Rotates the collisions and the sprites along slopes

			up_direction = get_floor_normal()
			
			rot = slope_steep

Sorry if this is a lot i have been stuck on trying to make a wall run that sticks the player to slopes for the longest time

You might check your CharacterBody2D’s settings. Especially the Floor settings.

Also, I never played Rayman, so i have no idea what you’re going for, but if you’re trying to change the gravity direction to a wall, gravity needs to be a Vector2() to account for the x-coordinate, not a float.

func gravity() -> float:
	return jump_gravity if velocity.y < 0.0 else fall_gravity

Also this code could result in weirdness because when the character is on the ground, gravity won’t be acting on them until they jump, which could cause collision problems. Changing that to a <= might solve some of your issues.

I think if I wanted to do something like this, I’d probably consider using paths; maybe run aPath2D along all the walkable areas (including up walls, the underside of platforms, wherever you want to be able to walk), and then rather than using normal “down” gravity, your gravity logic would be something like “find the closest path, find the closest point on that path, that’s the direction gravity pulls”.

I’ll try this out and see what happens, as messing with the gravity seems to have been what has been making the most progress

That could be an really interesting way to do it I might try that with a test character and see what happens