- Home /
Shump Touch Control
Hello Everyone!
I'm trying to do a Shump mobile game, and I downloaded some games from Google play like: BladeZ, Galaxy Aircraft, Galaxy Under Fire.
And I noted that all these games implement the same touch control (Which I found it perfect). You touch in any part of the screen, and if for example you swipe up, the airship moves up, is 8 direction.
SO, I'm trying to do this same control for my game, but is not working, can someone give me some guidelines?
This is whay I have so far:
Vector2 startPos;
Vector2 direction;
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
switch (touch.phase) {
case TouchPhase.Began:
startPos = touch.position;
break;
case TouchPhase.Moved:
direction = touch.position - startPos;
if (direction.x<startPos.x){
Vector2 pos=gameObject.GetComponent<Rigidbody2D>().position;
pos.x-=0.1f;
gameObject.GetComponent<Rigidbody2D>().position=pos;
}else if(direction.x>startPos.x){
Vector2 pos=gameObject.GetComponent<Rigidbody2D>().position;
pos.x+=0.1f;
gameObject.GetComponent<Rigidbody2D>().position=pos;
}
Debug.Log("Direction: "+direction);
break;
}
}
But is not working, any help is appreciated.
Thanks in advance!
You need to be a little more specific than 'not working'.
Hi,
Sorry, you're right I should be more specific.
When I touch the screen the airship only moves to left. I printed the direction and is always negative:
Direction: (-9.5, 2.6) Direction: (-14.7, 3.0)
So, I'm guessing my error is in this line: *direction.x
Your answer
Follow this Question
Related Questions
Possible to get touch area data? 1 Answer
Make object follow my finger (Touch)? 1 Answer
Working with screen's touch limit 0 Answers
Reset touch Vector after movement 2 Answers
Unity Touch Help! 0 Answers