Topic was automatically imported from the old Question2Answer platform.
Asked By
D
Old Version
Published before Godot 3 was released.
I want to set the rotation of a kinematic body to the surface normal from a raycast collision, which is a vector3. How can I turn a vector3 into a transform basis.
#Find the axis with the smallest component
var min_ind = 0
var min_axis = abs(normal.x)
if abs(normal.y) < min_axis:
min_ind = 1
min_axis = abs(normal.y)
if abs(normal.z) < min_axis:
min_ind = 2
var right
#Leave the minimum axis in its place, swap the two other to get a vector perpendicular to the normal vector
if min_ind == 0:
right = Vector3(normal.x, -normal.z, normal.y)
elif min_ind == 1:
right = Vector3(-normal.z, normal.y, normal.x)
elif min_ind == 2:
right = Vector3(-normal.y, normal.x, normal.z)
var up = normal.cross(right)
var basis = Matrix3(right, up, normal)