diff --git a/movement/look_rotation/example/look_rotation.script b/movement/look_rotation/example/look_rotation.script index cb959d6..84beffe 100644 --- a/movement/look_rotation/example/look_rotation.script +++ b/movement/look_rotation/example/look_rotation.script @@ -11,6 +11,11 @@ local function quat_look_rotation(forward, upwards) return vmath.quat() end + -- Handle alignment with up direction + if math.abs(vmath.dot(forward, upwards)) > 0.9999999 then + return vmath.quat_from_to(vmath.vector3(0, 0, 1), forward) + end + -- Create a rotation matrix from the forward and upwards vectors local matrix = vmath.matrix4_look_at(vmath.vector3(0), forward, upwards) @@ -61,4 +66,4 @@ function on_input(self, action_id, action) if action.pressed then next_target(self) end -end \ No newline at end of file +end