I am making a game where the player flies a balloon through a cavelike structure.

Balloon flies through maze

I am having trouble making him fly correctly when I try it out on my android tablet, seeing as it requires different input to move.

enter image description here

How can I make the player move towards the touched side? By creating a ray? through touched objects? :)

  • \$\begingroup\$ You could divide the screen and check for touch position in those areas and depending on which side of the screen the touch is on, move the player in that direction. \$\endgroup\$
    – Savlon
    Commented Nov 11, 2014 at 20:05
  • \$\begingroup\$ That sounds like it works. Any idea how I can execute this? \$\endgroup\$
    – Blobbey
    Commented Nov 11, 2014 at 20:12
  • \$\begingroup\$ Get the mouse x, check if it is either < windowwidth/2 or > windowwidth/2. Or, make your balloon follow the mouse x. \$\endgroup\$
    – Eejin
    Commented Nov 11, 2014 at 20:20
  • \$\begingroup\$ if (Input.touchCount < 0 && (Screen.width/2)){ rigidbody2D.AddForce(-Vector2.right*5); } Granted this gives me an error, but something like that? \$\endgroup\$
    – Blobbey
    Commented Nov 11, 2014 at 20:48

2 Answers 2


Following along with the other suggestions, you can use the screen width to determine the left or right side of the screen. I might also suggest using a dead spot around the balloon. Precision touching can be difficult. if you split the screen on a single column of pixels, touches near this divide might get registered on the wrong side of the line that the player wants.

This bit of pseudo code assumes that the balloon stays in the center of the screen and the background moves.

var leftBounds  : float = screenWidth/2 - balloonWidth/2;
var rightBounds  : float = screenWidth/2 + balloonWidth/2;
if (Input.touchCount > 0) {
    var touchPositionX : float = Input.getTouch(0).position.x;
    if (touchPositionX <= leftBounds) {
    if (touchPositionX >= rightBounds) {

If the balloon does not stay in the center of the screen, then the leftBounds and rightBounds will have to be calculated off of the balloons current position.

  • \$\begingroup\$ Is that javascript? anyways, I changed it to "float leftBounds" and stuff, removing all errors I could find, there's just one I can't seem to handle: "Screen.Width/2 - BalloonPlayer.Width/2;" (Unityengine.Screen does not contain a definition for width) \$\endgroup\$
    – Blobbey
    Commented Nov 12, 2014 at 5:56
  • \$\begingroup\$ You never specified the language, so I took a shot. No matter what the language, the problem is still the same. Are you using Screen.Width or Screen.width? \$\endgroup\$
    – Aholio
    Commented Nov 12, 2014 at 6:10
  • \$\begingroup\$ That is correct, and it was a mistake. It is C# that I am using. width with a small w worked. Can't believe I did not try that! Thanks a bunch. :) \$\endgroup\$
    – Blobbey
    Commented Nov 12, 2014 at 7:27

Using two different inputs (one finger and two fingers) for a same action (add a force) can be disturbing.

I would suggest you to only use one finger and orient the force accordingly to the touch position on screen.

As you seem to use Unity, you can easily get the touch position thanks to Input.mousePosition. Combined with Screen.width you will know if player has touched left or right side of the screen.

I don't know much about the actual gameplay of your game but with such technique it's easy to determine the actual force applied accordingly to the finger position... you could says something like "the closest of the border your tap is the biggest the applied force is"

I hope it helps.

  • \$\begingroup\$ I believe the gameplay will be most fun with the setup I am looking for. While one and two fingers work, I believe it will get frustrating and difficult for the players to pull off in a pinch. Moving towards finger position might work, but won't it be extremely hard for smaller devices? \$\endgroup\$
    – Blobbey
    Commented Nov 11, 2014 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .