restrict a drag with angles

I am trying ton limit a drag with this code

        --limit drag
        
        local function limit()
             local x = drwrGroup.x
             local y = drwrGroup.y
            
             if(x > 458) then
                  drwrGroup.x = 458
            elseif(x < 0) then
                 drwrGroup.x = 0
             end
                drwrGroup.y = 0
            
            
             end
        Runtime:addEventListener(“enterFrame”, limit)
    end

The problem is if the users drag is on an angle the object gets stuck. How can I limit the drag and allow for some angle?

Hi @doozystudios,

If I understand your intention, then removing the “drwrGroup.y = 0” line should solve this. With that, the group will not move past 0 or 458 on the X axis, but the Y axis will remain “unlocked” and the group will be able to slide up and down, even if one of the X limits is reached.

Take care,

Brent

Hi @doozystudios,

If I understand your intention, then removing the “drwrGroup.y = 0” line should solve this. With that, the group will not move past 0 or 458 on the X axis, but the Y axis will remain “unlocked” and the group will be able to slide up and down, even if one of the X limits is reached.

Take care,

Brent