How to aim at the point you're touching?

Hi,
I’ trying to develop a Sidescroller-Shooter Game.
I’ve got my Character equipped with a pistol.
The pistol is a child of an Empty Gameobject, that is in the middle of the Character, so that the Pistol can Rotate around it.

Now i want my gun to aim at the point, where I’m touching the screen.
But when I put the Touch.position data in to the new Vector3, where I want the Gun to aim at. It is somewhere in outer Space, like 512 on x.

function Guncontroll() {

	if(Input.touchCount > 0){
	var i : Vector2 = Input.GetTouch(0).position;

        

    aimpoint.position = (Vector3 (i.x, i.y, 0);

    gun.LookAt(aimpoint);
}
}

Hope someone could help me :slight_smile:

Input.GetTouch(0).position is the position on screen in pixels.

Use Camera.ScreenToWorldPoint to convert it into ‘world’ space

Scribe