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?