Throwing Enemies with Swipe

Lite

Member
Clicking on an enemy object picks them up and the enemy follows the mouse x/y until you release the mouse button at which time the enemy object calculates the direction and speed. This all works fine until I test on a mobile devices. About 2/3 when you throw an enemy they just drop because the speed is being set to 0, this especially happens when swiping very quick.

Is there a better way to calculate the speed and direction because of this?

Currently my control object to pick up and throw
Code:
if(pick = 1)  //Enemy picked up by clicking/tapping them
{
    swpdir = point_direction(mxs,mys,device_mouse_x(0),device_mouse_y(0));  //swipe direction
    swpspd = point_distance(mxs,mys,device_mouse_x(0),device_mouse_y(0))/1;  //swipe speed
    swpdist = point_distance(mxs,mys,device_mouse_x(0),device_mouse_y(0));  //swipe distance
    with(a)  //a is the enemy object selected
    {
        dir = other.swpdir;
        dist = other.swpdist;
        spd = other.swpspd;
    }
    if(device_mouse_check_button_released(0,mb_left))
    {
        pick = 0;
        with(a)
        {
            dir = other.swpdir;
            dist = other.swpdist;
            spd = other.swpspd;
            pick = 0; //no longer selected
            drop = 1; //dropped
            if(y < (sprite_height+25))
            {
                dzone = 1; //dropped high enough to destroy
            }
            motion_add(dir,spd);
        }
        a = noone; //no enemy selected
    }
    mxs = device_mouse_x(0); //x start loc
    mys = device_mouse_y(0); //y start loc
}
looks like this:
 
T

The Shatner

Guest
Hey man,
I was searching for more info on swiping these days and found a good tutorial about it:
.
See if that helps.
 

Lite

Member
Thanks for the reply Shatner, I actually use this same exact method for my swipe controls. It works perfectly for swiping the problem is that in this particular case the player picks-up and drags around the enemy and then throws so the X start and Y start value are constantly changing. If not the distance and direction variables gets all messed up because until the player lets go it wants to calculate distance. So currently to prevent this I just say when the enemy is 'picked' calculate everything then reset the X start and Y start every step which works.

The issue is just that half the time the player releases (device_mouse_check_released) the enemy and unknowingly stop their finger just quickly enough that the speed is set to 0 :( With a mouse it's super precise you either click or you don't, with a touch screen it doesn't read quite as precise sometimes.
 
Last edited:
J

Jaqueta

Guest
I'm not sure about that, it's just a theory, but my best guess is that the your touchscreen have a problem with the multi-touch
Basically, if you move your finger too fast, it will think that you used a second finger, instead of just swiping.

Try debugging this, create different effects on screen according to the device being used. If it shows different effects, my theory is correct.

The other way, is that your touchscreen sucks and won't get the right input every frame. :v
 

Lite

Member
Doing it on a brand new S7 Edge so I'm assuming it's not the screen hah. I'll definitely try debugging for multi touching, thanks!

UPDATE!:
The multi-touch isn't firing off so that's not the issue. I'm pretty positive it's literally because it's processing so fast that when you think you are moving your finger you really haven't in that split second timing so your distance in that step from the previous was 0. If you follow through it works nicely but this will be frustrating to players.
 
Last edited:
T

The Shatner

Guest
Hey Lite!
I am not sure I understood the problem correctly, but here goes: maybe you could add a timer (or alarm, or whatever measures time for you) so that the enemy is released only if the player releases the button *and* waits a few steps in zero speed. If it works, then your theory is correct. The actual implementation would probably require some fine-tuning, though.
 

Lite

Member
That is actually exactly what I did :D , though it's not 100% perfect the problem happens way less.
 
Top