Finding out if a Character is dragged left or right

I tried my first game with a character moving upwards on a Screen constantly (top-down view on a Road). Now I wanted to change the character animation to a strafe based on his movement to the left or right.

Problem is: the only available input is touch. So the player is dragged left or right (and a bit up and down) to avoid random obstacles.
Is there any way to determine if a player is dragged to one side more then lets say 10 Pixel? I could not figure it out.

Depending on how you change the position, there may be different possibilities. Are you using the behavior of ai and forces, ii just changing position?

Get the player’s position at touch start, and then work out the distance between that and the current touch position.

1 Like

@E1e5en Just the behaviour “draggable” on the object.

@MrMen That’s promising, but how can it be achieved? The player is dragged constantly around, so I cannot use “is being dragged” as trigger. So if the Player is dragged from x=300 to let’s say X=500 and then - without being released - dragged back to X=400 I would have to get the direction change at x=500 to change the animation from left to right.

Hi @_Patrick. I tried to make an example of the idea given by @MrMen and the result is this:

and the events are these:

This is how you get the direction of the object being dragged.


Thanks @Muzan
That worked really well.

1 Like