Player Aligning to gravity

Godot Version

4.2.1

Question

I have spent the last few hours on a 3rd person player that can move around no matter its orientation. This is for a game that will have planets much like Super Mario Galaxy. I have the gravity with an area 3d, and the player is a Ridgid Body 3d. My problem is I can not for the life of me get him to align to gravity.

I have been trying to use the center point of the planet to align my player to using the look_at future, and it almost works, but no matter what I do I find my character facing the center long way instead of with the bottom down. Suctch that it aligns the player with the center when moving, but it is his side.

func _physics_process(delta):

var GravPoi = planet.position
var GravVec = GravPoi - self.global_transform.origin #vector from player to planet center 

GravVec = GravVec.normalized()


var upVec = -GravVec + Vector3(0,-1,0) * 0.1
self.look_at(GravPoi, -upVec)

Here is an example for a character controller that uses spherical gravity. You will notice that it doesn’t use look_at, because that will lose information. Instead, we take the last rotation and up vector and rotate them directly.