Need help with 3D slope movement

Godot Version

Godot v4.2.1


The problem is when the player is moving on a slope, the movement vector stays parallel to the ground, but i want it to be parallel to the slope.

Is there a way to align the up vector with the slope normal?
Any help is appreciated

EDIT: This video shows what i am trying to accomplish but it’s for unity

Here’s a small tutorial about aligning a CharacterBody3D to the surface CharacterBody3D: Align with Surface :: Godot 4 Recipes

1 Like

This would work but i forgot to mention i’m using a rigidbody as the player, so i can’t use the align_with_y function that characterbodies inherit, thank you for the suggestion.

I ended up digging thru the docs and found the Quaternion(vec3 arc_from, vec3 arc_to) constructor so i just did what the video i linked did.

var input_dir = Input.get_vector("left", "right", "forward", "backward")
var direction = (head.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

var slope_rotation
if center_cast.is_colliding():
	slope_rotation = Quaternion(center_cast.get_collision_normal(), Vector3.UP).normalized()
	slope_rotation = Quaternion.IDENTITY

var adjusted_dir = direction * slope_rotation

linear_velocity += adjusted_dir * MOVE_SPEED