Преглед изворни кода

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