The bullet shoots from the wrong place

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?

Is the shoot location an empty game object that is childed to the character/gun?

1 Like

the shoot location is the transform position of the gun. I’ll try the empty game object trick.

Make sure it is out from the gun a bit so the collider on the bullet doesn’t overlap with the gun otherwise it will react with the collider on the player/gun

Yes! The empty game object trick worked! By the way the script says to ignore the player collider. My gun doesn’t have a collider yet but I’ll do the same thing for the gun collider.