I followed a script tutorial for bullets. It shoots well but shoots from the left of my gun. I tried to fix this by changing the transform.position but it won’t follow the rotation. For example, I said to move it slightly to the right so that the bullet shoots from the gun (Line 12). But when I turn to the left, the bullet will shoot from behing the gun and when I turn to the right, the bullet will shoot from the front of the gun and etc. I want that the position change follows my rotation so it always shoot from the gun.
Here’s the script :
var projectile : Rigidbody;
var speed = 20;
function Start () {
}
function DestroyProjectile ()
{
yield WaitForSeconds(6);
Destroy(gameObject.Find("rubberBullet(Clone)"));
}
function Update ()
{
shootLocation = transform.position - Vector3(-0.95, 0.1, 0);
if(Input.GetMouseButtonDown(0))
{
var InstantiatedProjectile : Rigidbody = Instantiate(projectile, shootLocation, transform.rotation);
InstantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, speed));
DestroyProjectile();
}
}
Can you help me?