Angle on local X axis (pitch)

MagicLordMagicLord Posts: 578Unconfirmed

Hi there,

I would need to get the angle on the local axis of a 3D model in space.
I have two raycast collision 3D points, one on front , one on rear , how can i have the pitch of those two raycast ?
How to rotate a 3D object to that absolute pitch on it's YZ local plane ?

I read some tutorials but i didn't figured out to combine some code snippets to get it work.


  • MagicLordMagicLord Posts: 578Unconfirmed
    edited March 26 Answer ✓

    I found a solution using normals to align the object to ground variation

    normalBack = normalBack.linear_interpolate( rayBack.get_collision_normal(), 0.5)
    normalFront = normalFront.linear_interpolate( rayFront.get_collision_normal() , 0.5)
    normalBAckL = normalBAckL.linear_interpolate( rayBackL.get_collision_normal(),0.5)
    normalFrontL = normalFrontL.linear_interpolate( rayFrontL.get_collision_normal(),0.5)

    var normalMedium = (normalBack + normalFront + normalBAckL + normalFrontL).normalized()

    var oldTranform = transform

    look_at(transform.basis.z, normalMedium)
    var newTransform = transform

    transform = oldTranform.interpolate_with(newTransform,0.8)

Sign In or Register to comment.