|
@@ -3,14 +3,22 @@ function init(self)
|
|
|
msg.post(".", "acquire_input_focus")
|
|
|
end
|
|
|
|
|
|
-function on_input(self, action_id, action)
|
|
|
- -- the position to look at (mouse/finger)
|
|
|
- local look_at = vmath.vector3(action.x, action.y, 0)
|
|
|
+local function look_at(target_position)
|
|
|
-- own positon
|
|
|
local my_position = go.get_position()
|
|
|
|
|
|
-- calculate the angle that this object has to rotate to look at the given point
|
|
|
- local angle = math.atan2(my_position.x - look_at.x, look_at.y - my_position.y)
|
|
|
+ local angle = math.atan2(my_position.x - target_position.x, target_position.y - my_position.y)
|
|
|
-- set rotation as a quaternion
|
|
|
go.set_rotation(vmath.quat_rotation_z(angle))
|
|
|
+end
|
|
|
+
|
|
|
+function on_input(self, action_id, action)
|
|
|
+ -- mouse/finger movement has action_id set to nil
|
|
|
+ if not action_id then
|
|
|
+ -- the position to look at (mouse/finger)
|
|
|
+ local target_position = vmath.vector3(action.x, action.y, 0)
|
|
|
+ -- rotate this object to look at the target position
|
|
|
+ look_at(target_position)
|
|
|
+ end
|
|
|
end
|