Tap where you want to shoot.

Hi there everybody. I am currently deveoping a shooter for iPhone called Piveck. The camera is above you and you move around with a joystick in the bottom left hand corner of the screen. I want it to be set up so you tap (click) anywhere on the screen and the character controller with a gun in his hand turns to face where you tapped, Then he shoots. If you continue holding I want him to continue firing. And I want it so you can change your aim while firing by moving your finger with machine guns.

Does anyone know how to do this? If possible, please leave your answers in C#, but Javascript and Boo are fine. Thank you.

This question comes up fairly frequently so I would search the UA for top down shooter facing a point. But I can give you a very simple example of what you want to do.

public void RotateTowardsPoint (Vector3 point) {
      Vector3 target = point - transform.position;
      Quaternion targetAngle = Quaternion.LookRotation(target);

      transform.rotation = Quaternion.Slerp(transform.Rotation, targetAngle, Time.deltaTime);
}

Like I said, this is a very simple example. It just centers the point on the player (which you should cache a reference to). Creates a rotation facing that point. Then interpolates the players current rotation to that rotation. This isn't psuedo-code, but I would treat it more like an example of the general approach than the final solution since I just quickly put it together. There is some more tweaking to do.