Another issue is you are aligning them by shootDirection but then imparting force by shootDirection * speed + shipVelocity
Is that the problem?
You don’t need to really impart force either: you can just set the .velocity
directly… I prefer that since when I hear AddForce I think “I am shoving this” when really what you are doing is setting the velocity.
Also you can remove the duplicate code for left / right fire pretty easily.
It would go something like:
if (angle okay to fire)
{
if (cooldown timer expired)
{
// toggle sides
leftSide = !leftSide;
// presume right side
Vector3 launchPoint = rightLaserSpawn.position;
// except when left!
if (leftSide) launchPoint = leftLaserSpawn.position;
// now all the standard launch code, but use launchPoint as a proxy for left / right above
}
}
Just say “no” to duplicate code.
I also recommend NOT using Time.time for cooldowns. Just set it to nonzero when the gun is cooling and then count down Time.deltaTime until it gets at or below zero. It makes the numbers always 0 to X instead of ever-advancing.
Cooldown timers, gun bullet intervals, shot spacing, rate of fire:
GunHeat (gunheat) spawning shooting rate of fire: