How I can rotate game object on dragging horizontally?
Below clip is just using “look at” example but this was not something I wanted. Ability to drag from any point on screen horizontally will rotate object from initial angle point.
On press, store the x position of the input. On each subsequent frame calculate the delta (difference between current x and previous x), then apply rotation accordingly. Then finally store the current x, and compare it to the next one etc etc.
Something like this:
if action.pressed then
self.last_x = action.x
end
if self.last_x then
local delta = action.x - self.last_x
local rotation = go.get(go.get_id(), "euler.z")
rotation = rotation + 10 * (delta/50)
go.set(go.get_id(),"euler.z", rotation)
self.last_x = action.x
end
if action.released then
self.last_x = nil
end