- Home /
Getting hit with two bullets cause the game to crash [Solved]
Solution: I screwed up and at one point I was using random to generate a number from 1 to 3 and if it couldn't preform action 1 it would add 1 to the random number to do action 2 and so on. However, it appeared as if I was always hitting all of one action so to mix it up a little I made it go from 1 to 99 but I still had it only add 1. which means if it rolled a 1 and it could not preform action 1 it would keep adding one until it got to 34. Same for action 2 to 3 and 3 back to 1. Note: if it can't preform any of the action the formula would completely ignore this step all together.
In sort, I have a player that is hit with two bullets at the same moment and at that moment my game completely crashes or only registers one of the two bullets and ignores the other one. NOTE: when it only collides with one bullet everything works fine with no issues.
I am using OnTriggerEnter to preform the various actions that will happen when the player is hit by a bullet. I know this is a monster wall of script but I think I presented the main problem but here it is if it helps.
Check that lines 85 and 101 don't put you into an infinite loop
You really should split that code up into several functions. $$anonymous$$akes it a whole lot easier to read plus you can ensure that each function works correctly before putting it all together.
Thank you getyour411. I did noticed I screwed up (because I'm lazy and use copy/paste) and had randNum >= 1 && randNum < 34 && in a lot of places it shouldn't be. I have fixed that and I will update the post soon. To kork, I have tested this with one bullet and saw that every line of code appeared to work under any condition but it only seems to crash when I have two bullets. I have not tested 3 or more but I doubt it will make much difference. I probablly could chop this up but like I said I believe this problem is not with my code but possible something wrong with OnTriggerEnter. I could wrong or may be wrong in using that. I know of oncollisionenter but long story sort I had a big fight with it and OnTriggerEnter wasn't giving me a problem.
NOTE: I am still having a problem. I just wanted to thank you for noticing some mistakes.
Answer by orangeflame · Sep 04, 2013 at 01:52 AM
Sorry everyone it turns out it was just an error in code and I literally got bad luck because of the random function and I must have always rolled a good number when testing the single hit.
Your answer
Follow this Question
Related Questions
Trigger and Collider Issues 1 Answer
OnTriggerEnter not working 0 Answers
Layers, parenting and collisions. 0 Answers
OnTriggerEnter not firing 1 Answer
percentage health bar 1 Answer