I'm having some trouble with the weapons I'm implementing in my game. At first I didn't notice the problem because I was emitting so many of them, it seemed to be working as expected... but when I added a cooldown to a new weapon I made, I noticed that all the particles were bunching together and traveling on the same angle. I'm honestly not sure what the problem is, because I've used console printouts to see what the data is, and it all seems to be fine.
Here is the Github project with all the code. The relevant files will be listed below.
Relevant Files (as far as I know):
- genericzombieshooter.structures.weapons.Shotgun (same problem with Flamethrower)
I'm not positive that the problem lies in those files, but I'm almost sure that the problem is within one of these methods.
- update() method
- fire() method
- updateWeapon() method
Obviously, it's a large project, so I expect questions, so let me know if you need more information, because I just don't know where to look for the problem. I'm pretty sure it has something to do with moving them, but like I said, there's no guarantee. Also, these are some anomalies I noted while playing around:
- Obviously, the biggest problem is that the particles "bunch together" and move along the same angle. The idea for moving them was to give them a "spread" value, which is then multiplied by a random double (0.0 - 1.0) to get a random value between 0 and the PARTICLE_SPREAD value. Then this is multiplied by -1 if the "mod" variable is true, so it can go either PARTICLE_SPREAD or -PARTICLE_SPREAD degrees away from the origin angle. This value is then added to the theta stored within the Particle object. To move the particle, I simply got the sin of the X value of the position variable and the cos of the Y value and multiplied them by the speed, then added them to the current position. I've used this too many times to think there's something wrong with it.
- When the particle creation is reduced to a single particle (for loop commented out) and the values kept the same, the particles move extremely slow compared to while it's in the loop, almost as if the number of iterations has some bearing on the speed... but the speed provided is a literal value. I used an iterator to iterate over the particles when updating them, and I was wondering if for some strange reason, only one particle is being updated multiple times.
There may be other anomalies I'm not aware of. Any help is appreciated!
P.S. Image is not of the problem... just thought I'd attach a screenshot for you to look at.
Edited by PaCkEtPiRaTe, 09 August 2013 - 05:37 PM.