Skip to main content


Showing posts from May, 2014

Simple swipe in unity using angle calculation for touch devices

Today i am gonna post on how to do Simple swipe using angle calculation in unity for touch devices.

as you can see in the image every direction have a touch area of 60' so if your swipe falls in that area, than according to your conditions, respective swipe gesture will be called.
To use the below given script, attach it to an empty gameObject and than drag your player to the player variable in the inspector and check the results.


publicclassSwipeSimpleCS : MonoBehaviour {

publicTransformplayer; //Dragyourplayerhere
privateVector2fp; //firstfingerposition
privateVector2lp; //lastfingerposition

voidUpdate () {
if (touch.phase == TouchPhase.Began)
fp = touch.position;
lp = touch.position;
if (touch.phase == TouchPhase.Moved )
lp = touch.position;
swipeDistanceX = Mathf.Abs((lp.x-fp.x

Joysticks for touch devices in unity

Hi guys this time i am gonna post on joystick for touch devices. Usually you have seen joysticks in unity like this picture.

With those joysticks it lacks accuracy, you can hardly start with (0,0,0) as your input for horizontal or vertical movement. I played few games in my android device and i observe that they don't use these joysticks. So i was excited to know how they do it. I searched on the internet but there were not much on this topic.
Than a simple idea came to my mind. Why not divide the screen into half's and use one half for movement and one half for rotation ? This solved the issue i was facing with touchpads. With different resolutions touchpad's size also get differ.
But now i have the basic idea and that idea need to be bring into reality. So i started working on it and after a day work i got the basics right and my joystick script was working well. My aim was to do something like you see in dead trigger 2, i will not say its 100% like that, I am leaving the d…