Hey Guys,
Iam in trouble, I have written a script which casts a ray to the Screens middle, where my crosshair is placed.
Sometimes the “Balls” flying exactly to this position and sometimes they’re flying anywhere beside the crosshair. I tried to find the error with Debug.DrawRay in the following Script, but the Ray isnt draw anywhere:
var ammo : Rigidbody;
var gun : Transform;
var ammoSpeed = 500.0;
function Shoot()
{
var hit : RaycastHit;
var ray = camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
if(Physics.Raycast(ray, hit, 100))
{
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.green);
}
ammoClone = Instantiate(ammo, gun.position, gun.rotation);
ammoClone.rigidbody.velocity = ray.direction * ammoSpeed;
could anyone help me outa here?