Need help with aligning my character to surface normal

There is a problem when I converted the code from this website CharacterBody3D: Align with Surface :: Godot 4 Recipes to C#. The formula works but just bearly, this is the function code
private Transform _bruh(Transform Xform, Vector3 normal)
Xform.basis.y = normal;
Xform.basis.x = -Xform.basis.z.Cross(normal);
Xform.basis = Xform.basis.Orthonormalized();
return Xform;

skeleton.GlobalTransform = _bruh(skeleton.GlobalTransform, Ground_Normal);

The kinamtic body rotates to the surface normal but it does not rotate to it correctly leaving the body rotated just alittle bit off to the side. Making the body slide around the floor like it’s ice or somthing. Please help me with this I don’t know why it’s doing this.

I think in that tutorial they use a special snap function to keep from sliding.

Godot 4 the snap? Settings changed

are you talking about this?


In the link you posted I think it’s an older Godot that had this function.

That no longer exists and was replaced by other functions.

As far as you other issue with orientation. I think your code is right.

You just need to make sure set the transform back to the owner, because transforms are passed by value.

I think your last post you did do that…

I would make sure you are using global_transform.

Imo I think that method is a little strange they make you change the basis and orthonormalizing it. But I guess which axis is used to “square” the basis? Maybe that is the issue…

If I were to do this I would use the looking_at function. Using the global basis.z + origin as the target. And the “up” your normal.

var target_xform := plyr.global_transform.looking_at(plyr.global_position-plyr.global_basis.z, normal) # using -basid.z should put point in front of player to look at but we just really want the "up" to change
plyr.global_transform.interpulate_with(target_xform, lerp_rate)

I think if you avoid modifing the basis directly, and hoping orthonormalizing will work as intended, you may get a better result.

I think there could be another trick here, but my gut thinks the direct basis modification is the issue.