瀏覽代碼

Handle alignment with up direction in the Look Rotation example (#91)

* Handle alignment with up direction in look_rotation.script

* Update look rotation alignment threshold
Artsiom Trubchyk 2 月之前
父節點
當前提交
81d49343fa
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      movement/look_rotation/example/look_rotation.script

+ 6 - 1
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_id == hash("mouse_button_left") and action.pressed then
 		next_target(self)
 	end
-end
+end