Let KinematicBody rotation follow a slope?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AncientPixel

Hi there;
i have a 2d focused background and want to dive into 3d :slight_smile:

i use a KinematicBody with move_and_slide for my boat style movement - this is simple and works great. Now i want to rotate the Mesh and CollisionShape to match the rotation of the floor.
Imaging going from a flat surface onto a ramp in a car or a boat. I´ve got a raycast stuck on the belly and get the collision normal and the rotation of the colliders mesh, but i dont get the rotation to be correct.
I suspect i only need two axis of the rotation, because i want to still turn around my local y axis?

these ar some ways i tried it:

#ray method
if ray.is_colliding():
	var collider = ray.get_collider()
	#$CollisionShape.rotation = Vector3(collider.get_parent().get_parent().rotation.x, collider.get_parent().get_parent().rotation.y, collider.get_parent().get_parent().rotation.z)
	# or : 
#$CollisionShape.look_at_from_position($CollisionShape.global_transform.origin, ray.get_collision_normal(), Vector3(0, 1, 0))
	if Input.is_action_just_pressed("ui_select"):
		print("data:")
		print(ray.get_collision_normal())
		print($CollisionShape.rotation)

#collision method
var hitCount = get_slide_count()
if hitCount > 0:
	var collision = get_slide_collision(0)
	if collision.collider is StaticBody:
		$CollisionShape.transform.basis = Basis(-collision.normal)#or
		$CollisionShape.rotate_object_local(Vector3(0, 1, 0), collision.collider.transform)