can't believe there isn't an easier way to accomplish particular swipe directions.
Swipe direction is easy but you also want to know if an object has been swiped or not? There is maybe some sort of math solution to this but I'm not very good at math. You may want to PM Lizard-13, he/she is the mathematician around here.
To determine swipe direction only all you need to do is store the initial position of the touch in a variable and then compare the value to the current position of the touch:
Code: Select all
If mouse button is down, or touch held : Do = MouseX() to variable initialTouchX
Trigger Ounce :Do = MouseY() to variable initialTouchY
If MouseX() > Variable(initialTouchX) then swiped to right
If MouseX() < Variable(initialTouchX) then swiped to left
If MouseY() > Variable(initialTouchY) then swiped down
If MouseY() < Variable(initialTouchY) then swiped to up
And then you can combine this to also get if swiped diagonally and set initial value to 0 or something when the touch is released so you know the user is no longer swiping. But it is only direction, in order to know if there was an object swiped, I don't know any better ways right now than create an invisible object or cast a ray from initial to current. Maybe you could also just check if the user is swiping (if initial position and current position is different that means the user is swiping) and an object been touched in position of current touch then the object been swiped.
I would be also interested to know if there is some fancy math solution to this. Please let me know if you got something.
Actually, if all you want is sort of drag and throw objects off the screen with a swipe, you could use the draggable behaviour to help with initial movement and then finish it off with forces toward direction of swipe once the object is no longer dragged. You can use an object variable to flag the object to be swiped off once it dragged and then once the object no longer dragged simply move it off the screen toward the direction of swipe. You can either take a note of the X and Y value of the touch and calculate angle from it or rotate object toward position of touch and then move object off the screen toward it angle.