if game.CurrentScene.Objects["example"].Offset.x == 0 and game.CurrentScene.Objects["example"].Offset.y == 0 then
game.CurrentScene.Objects["example"].Offset = {x = 100, y = 100} --- move object to correct starting position
end
function drag_itm()
game.CurrentScene.Objects["example"].Offset = { x = getCursorPos().x + 100, y = getCursorPos().y + 100 }
end
registerEventHandler("mainLoop", "drag_itm")
unregisterEventHandler("mainLoop", "drag_itm")
game.CurrentScene.Objects["example"].Offset = { x = getCursorPos().x + 100, y = getCursorPos().y + 100 }But I only want to pick up an object that my cursor is above. However, if I type
game.CurrentObject.Offset = { x = getCursorPos().x + 100, y = getCursorPos().y + 100 }
It's not really viable to just check for the object below the cursor because you don't know how fast the player will be moving their mouse around, or what dpi, etc. so it's possible that the player drags too fast & the cursor ends up shooting past the object & also you wouldn't be able to offset it either.I get your point. However, pressing the left mouse button far away from the object and then having the object just appear/ jump to the cursor is not really the effect I was hoping to get. I was thinking to achieve a mechanism in which you can only pick up an object and drag it around if your cursor was above the object before you pressed the mouse button.
In regards to boundaries, what exactly do you have in mind? Are they supposed to prevent the object from being moved past the boundaries, or if the player lets go of the mouse button outside of the boundaries is the object supposed to go back to the default position?
function mainLoopCursor()
if Conditions.LM_pressed.Value and getCursorPos().x < 200 then
local pos = getCursorPos()
pos.x = 200
setCursorPos(pos)
end
end
registerEventHandler("mainLoop", "mainLoopCursor")