Charecterbody2d rotational vector matching? relative stuff?

Godot Version

godot 4 web

so i am trying to make a small game as a side project and it has some pretty i would say not normal physics. basicly the player is a slime and i want them to basicly stick to walls floors or ceilings. i currently have the player rotate based on the floor angle its on using the get_floor_normal().angle() function. this works fine on the floor or on the ramps but the issue comes from the walls i just cannot get it to do the same. in code gravity should be disabled when hes on a surface and replaced with relative gravity and the movement should also be relative but it appears not to be. i have tried to get the jump relative but it also doesnt seems to work and when i am jumping it i hit the roof it rotates but not correctly it put the slime like 90 instead of 180.
ive been trying for 2 days but coudnt figure it out, please help

code:

var surfacerotation = 0
const SPEED = 60.0
const JUMP_VELOCITY = -400.0
var slimestate: String = “idle”

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):

# Add the gravity.
if not is_on_floor() and not is_on_wall() and not is_on_ceiling():
	velocity.y += gravity * delta
else:
	var relative_gravity = Vector2(0, gravity).rotated(rotation)
	velocity += relative_gravity * delta 
	

# Handle jump.
if Input.is_action_just_pressed("ui_accept"):
	if is_on_floor() or is_on_wall() or is_on_ceiling():
		var relative_jump = Vector2(0, JUMP_VELOCITY)
		velocity = relative_jump


# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.


if Input.is_action_pressed("ui_left"):
	if is_on_ceiling() or is_on_floor() or is_on_wall():
		velocity.x = -SPEED 
	slimestate = "walking left"
	$"slime sprite/slimeAnimationPlayer".play("slime walk left")

elif Input.is_action_pressed("ui_right"):
	if is_on_ceiling() or is_on_floor() or is_on_wall():
		velocity.x = SPEED 
		slimestate = "walking right"
		$"slime sprite/slimeAnimationPlayer".play("slime walk right")

else:
	if is_on_ceiling() or is_on_floor() or is_on_wall():
		velocity.x = 0
		$"slime sprite/slimeAnimationPlayer".play("slime idle")
		slimestate = "idle"
if is_on_floor() or is_on_ceiling():
	surfacerotation = get_floor_normal().angle()
if is_on_wall():
	surfacerotation = get_wall_normal().angle()
rotation = surfacerotation + PI/2

Vector2(velocity).rotated(rotation) 
move_and_slide()

also if it matters the colision stuff is tilemap

I doesn’t know about problem but here is mistake.
Must be

velocity = velocity.rotated(rotation) 

probably on the right track but dammmm did that break everything to hell, ill look into it

ok so after hours and days or trying to change things the code has gotten very messy so i deleted it all so im now blank but i still am stuck so please point out and issues with the above code so that i can try and recode it all

Can only give advice. Not have ready to use solution.
CharacterBody2D have a property up_direction, collisions are relative to up_direction , by default up_direction is Vector2.UP, so collision can be wall(if if left or right), ceil (if it upper) or floor(if it below). Basic idea is define gravity vector base on is_on_wall, is_on_ceil, is_on_floor and use it to apply it for gravity and movement and also appy up_direction = -gravity_vector. But keep in mind if you rotate CharacterBody2D it also rotates up_direction