I have this script attached to a gun, that shoots a sphere(bullet) from an empty GameObject named “Spawner” in front of it.
The problem is that when I press the mouse button, the bullet has a wrong direction, as the image shows bellow. Why is this happening?
Preview:
This is the script that I use:
#pragma strict
var bulletPref : Rigidbody;
var bulletPos : Vector3;
var spawner : GameObject;
function Start () {
}
function Update () {
bulletPos = spawner.transform.position;
if(Input.GetMouseButtonDown(0))
{
var clone : Rigidbody;
clone = Instantiate(bulletPref, bulletPos, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * 20);
}
}