Instantiate at Location Problem

void Update()

{

	if(Input.GetKey(KeyCode.Space))
	{
	       fireCounter += Time.fixedDeltaTime;
				
			if(fireCounter >= fireRate)
			{
				fireCounter = 0;
					
				MachineGun();
			}
	}
	
}
	
void MachineGun()  
    {   		 
     Instantiate(fastProjectile,gun.transform.position,gun.transform.rotation);
	}

This is my code I have. Whenever I hold space bar my object sometimes gets instantiated at the object location “gun” and sometimes it instantiates 2 units below the object location “gun.” I don’t understand why because all I have for gun is this tiny cube without any colliders so it’s not as if the “fastProjectile” is being pushed by the gun to 2 units below. My bullet is a tiny cube so I don’t think it has anything to do with that either.

Any suggestions?

Ok, my problem was I didn’t have my prefab centered at (0,0,0).

Your bullets are colliding with each other. You can have multiple updates between any fixedupdate. Slow down the rate of fire to at most one bullet per fixedDeltaTime, or better, either set a flag in FixedUpdate and clear that flag in Update or keep the lastBulletFired as a static and verify that it’s transform is NOT the spawnpoint before allowing a firing.

CORRECTION:Keep LastBullet a private variable, it doesn’t have to be static.