My character should always look at the mouse cursor, but after the character moves, he stops looking at the cursor.
function look_at(target_position, my_position, turn_object)
local angle = math.atan2(my_position.x - target_position.x, target_position.y - my_position.y)
go.set_rotation(vmath.quat_rotation_z(angle), turn_object)
end
function on_input(self, action_id, action)
local target_position = rendercam.screen_to_world_2d(action.screen_x, action.screen_y)
look_at(target_position, go.get_position("/Player/visual"), "/Player/visual")
go.set_position(target_position, "/Player/go")
local dt = 1/60
if action_id == hash("W") and not Console then
go.set_position(vmath.vector3(go.get_position().x, go.get_position().y + Speed_Mult * dt, 0))
elseif action_id == hash("S") and not Console then
go.set_position(vmath.vector3(go.get_position().x, go.get_position().y - Speed_Mult * dt, 0))
elseif action_id == hash("A") and not Console then
go.set_position(vmath.vector3(go.get_position().x - Speed_Mult * dt, go.get_position().y, 0))
elseif action_id == hash("D") and not Console then
go.set_position(vmath.vector3(go.get_position().x + Speed_Mult * dt, go.get_position().y, 0))
end
end
I have looked through all the questions on this topic, but I have not found an answer.