# Converting screen coordinates to world coordinates

I have a very basic problem that I cannot find an answer for anywhere. I’m making a snake style game with a few twists for android. The issue is that whenever I touch on screen, my “snake” will only go in two directions it thinks I’m touching way off the screen in the world coordinates.

Here I tried using the only convert method I could find, however this makes it so the the touch is converted to where the camera is which is the center of the screen.

``````var touch : Touch;
var worldTouchPos : Vector3;

for (var i = 0; i < Input.touchCount; ++i) {

touch = Input.GetTouch(i); ~~~~

worldTouchPos = camera.main.ScreenToWorldPoint(touch.position);

if(touch.phase == TouchPhase.Began)
{
if(direction == 0 || direction == 2)
{
if(transform.position.y < (worldTouchPos.y)) // Go up or down
{
direction = 1;
}
else
{
direction = 3;

}
}
else // go right or left
{
if(transform.position.x > (worldTouchPos.x))
{
direction = 2;
}
else
{
direction = 0;
}
}

}

}//end for

if(direction == 0)//right
{
transform.Translate(Time.deltaTime, 0, 0);
}
else if (direction == 1)//up
{
transform.Translate(0, Time.deltaTime, 0);
}
else if (direction == 2)//left
{
transform.Translate(-(Time.deltaTime), 0, 0);
}
else if (direction == 3)//down
{
transform.Translate(0,-(Time.deltaTime), 0);
}
``````

If I just use touch.position.x and touch.position.y where worldTouchPos is, then thats where it will go two directions and out of the screen.

How can I make it so my touch is exactly where it is in the game world coordinates?

Try this: