# How do i implement 8 direction swipe function

**URL:** <https://forums.unrealengine.com/t/how-do-i-implement-8-direction-swipe-function/423415>\
**Category:** Mobile\
**Tags:** swipe, Mobile, unreal-engine, UE4, Blueprint, question\
**Created:** [April 24, 2018, 1:57am UTC](https://forums.unrealengine.com/t/how-do-i-implement-8-direction-swipe-function/423415 "2018-04-24T01:57:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian\_p](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adrian\_p](https://forums.unrealengine.com/u/adrian_p)\
**Post date:** [April 24, 2018, 1:57am UTC](https://forums.unrealengine.com/t/how-do-i-implement-8-direction-swipe-function/423415/1 "2018-04-24T01:57:43Z")

</div>

![238604-vectorcompass.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/d/c1d7fe63540ccaf31877553f1193aba9ecf1af5b.jpeg)

hey guys,  
I am trying to implement swipe functions into my game, so essentially determining whether the person swipes **N, NE, E, SE, S, SW, W, NW** and then outputting into a function based on the direction they swipe.

I have figured out how to do **N, E, S, W** (up, down, left, right)  
however, I am stuck on the diagonal functions. (NE,SE,SW,NW)

Hope that makes sense, Thanks guys

 ![yOi7Wbl.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/c/5c1bd0f1683466bc83788e84d8915c6b7b79c170.jpeg)

---

<div class="post-metadata">

**Author:** ![goncasmage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@goncasmage](https://forums.unrealengine.com/u/goncasmage)\
**Post date:** [April 24, 2018, 4:25pm UTC](https://forums.unrealengine.com/t/how-do-i-implement-8-direction-swipe-function/423415/2 "2018-04-24T16:25:57Z")

</div>

- Subtract the position the player concluded the swipe in with the position he started the swipe in (you already do this)
- Check the angle between that Vector2D and the (1 ,0) Vector2D. You can do this by using the DotProduct: [https://answers.unrealengine.com/questions/31058/how-to-get-an-angle-between-2-vectors.html?sort=oldest](https://answers.unrealengine.com/questions/31058/how-to-get-an-angle-between-2-vectors.html?sort=oldest)
- Use this image to calculate the direction:

 ![238660-help.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/3/5832c176cc4075026b3408905006016a972a28c0.png)

---

<div class="post-metadata">

**Author:** ![adrian\_p](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adrian\_p](https://forums.unrealengine.com/u/adrian_p)\
**Post date:** [April 26, 2018, 11:05am UTC](https://forums.unrealengine.com/t/how-do-i-implement-8-direction-swipe-function/423415/3 "2018-04-26T11:05:48Z")

</div>

ok so i tried the acos approach and it didnt seem to be working out so i done some research and tried the atan2 function instead with the broken up X & Y values and now works perfectly. thank you so much for your help 🙂
