# Swipe Touch Motions

Hello, I’ve looked this up but info on it is scarce. I’m not sure how to do swipe motions (on touchscreens, ie). I’ve fiddled with new touch, end touch, variables, global variables touch identifiers, etc, for a few nights now and cannot figure out how to simply swipe an object. (Particularly swipe an enemy off the screen to destroy it). Any help would be very appreciated, Thank you.

Probably there is a more elegant way to do this but what I would do is create an invisible object in the initial position of touch, and then as you swipe, rotate and scale the object toward the current position of the touch. If this object (swipe object) is in collision with an enemy, that means the enemy must be swiped and destroy the enemy. Once the touch is released, delete this invisible object.

Or maybe you could also use raycast, to cast a ray from initial position of the touch toward the current position of the touch, if the ray hit the enemy then the enemy probably been swiped and you can delete the enemy.

Thanks @ddabrahim I’ll try it out. I just can’t believe there isn’t an easier way to accomplish particular swipe directions. I should mention that that’s the core of my game, swiping multiple enemies off the screen. so this is fairly important. lol!

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]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
[/code]
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.