I am using raycasts to make a gun but I want the bullets going to the centre of the screen. I saw a fragment of a code to do this. I am new to raycasting, and help would be appreciated.
var crosshair : GameObject; // game object that goes where the ray collides. make this an empty game object.
var bullet : GameObject;// the projectile being fired.
var pnt : GameObject; // point where bullet is instantiated from. place this object where you want bullet to fire from.
function Update () {
var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 10000)) {
Debug.DrawLine (ray.origin, hit.point);
crosshair.transform.position = hit.point;
pnt.transform.LookAt(hit.point);
}
Instantiate(arrow,pnt.transform.position,pnt.transform.rotation);