Those red planes are somehow firing Stealth Bullets, which means the player can’t see the bullets and it makes not dying a whole lot harder.
My untrained eye sees nothing at fault with the code or the setup of the sprite,
Most annoyingly is that it is not a 100% guaranteed bug. If I do something related to player input, like move the plane or shoot off a few rounds before the first enemy plane appears on the screen then I sometimes get visible bullets. The difference is plain to see in the two attached images. These are obviously two different executions of the code because the bug doesn’t start or go away after the first bullet is fired. I’ve left the usual print(“”) s to the console in to make sure that the proper functions are being called and executed.
I’ve been trying to sort this one out for a couple days. Can anyone help?
I’ve actually got a pretty wide range of Z-orders going on. But the enemy bullets have a Z-order of 1, and practically everything else is in the range of 0.1 to 0.7 (mostly because I thought the whole two layers of cloud would look cool). If the Z-order of 1 gets overwritten by the enemy planes’ Z-order because the bullets are spawned the enemy plane script then I might have a problem.
I realized after posting that my question was useless without source code, so here it is: the latest version of my project. The project seems to have bloated somewhat. I’m not sure why.
The keys to press to get the bullets to work seem to be a couple or more taps of the Left arrow followed by a few taps of the space-bar, all before the first red plane appears on the screen. So you have about two seconds. I HAVE NO IDEA WHY THAT WORKS. I used to test (break) software for a living and short of malicious code I can’t think of any reason WHY this works. Especially because I wrote this and I’m pretty sure I didn’t leave that in.
As I mentioned before, this is because of z-fighting.
I added some print("Bullet position:", pos) statements for your bullets and enemy planes, and the result is:
Enemy Position: vmath.vector3(164.27215576172, 1146, 0)
DEBUG:SCRIPT: Enemy Position: vmath.vector3(405.03662109375, 1146, 0)
DEBUG:SCRIPT: enemy should be shooting bullet
DEBUG:SCRIPT: Bullet position: vmath.vector3(164.27215576172, 789.87316894531, 0)
DEBUG:SCRIPT: enemy should be shooting bullet
DEBUG:SCRIPT: Bullet position: vmath.vector3(164.27215576172, 570.88049316406, 0)
DEBUG:SCRIPT: Enemy Position: vmath.vector3(208.97735595703, 1146, 0)
DEBUG:SCRIPT: enemy should be shooting bullet
DEBUG:SCRIPT: Bullet position: vmath.vector3(405.03662109375, 789.97991943359, 0)
DEBUG:SCRIPT: enemy should be shooting bullet
DEBUG:SCRIPT: Bullet position: vmath.vector3(164.27215576172, 354.88125610352, 0)
All of your enemies and bullets have the same Z value of 0. Also, guess what else has a Z value of 0? Your sea game object. Because of that, they sometimes appear behind the sea and sometimes on top of it.
If you give your bullets a slightly different Z value (since they should be rendered above the sea), for example 0.1, the issue is fixed. You should also give enemy planes a different Z value, such as 0.2, so you won’t run into similar issues.