0 votes

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

i use a KinematicBody with moveandslide 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)
asked May 17 in Engine by AncientPixel (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.