|
Hello, I am making a game with a character who has four types of bullets, one of which gives a small damage but passes through the enemy. My problem here was that whenever I fired the bullet it stuck to the first enemy itself and destroyed itself after the time I set. To counter this I thought maybe I could set the gameObject.isTrigger = true whenever the collision happens, so the bullet would pass through it and when it is out of the object I set gameObject.isTrigger = false, so that it would turn on collision physics again. Now whenever I run the game and fire that bullet, it hits the first enemy and then unity simply crashes. Because of that, I haven't been able to find the error as well. Can you please suggest any other method that might be more successful, or a correction for the code I used which I have written below, if(bullet.gameObject.name == "stunbullet"){ all the other types of bullets are working fine except the pierce bullet which should go through the enemies. Help would be most appreciated
(comments are locked)
|
|
use whole thing is worked out for you, with that method. Documentation can be found here worked perfectly. Thanks a lot.
Jul 31 '12 at 05:34 PM
Niluk93
No prob :)
Jul 31 '12 at 08:55 PM
DESTRUKTORR
how did u manage to decrease the enemy's health if you ignore collisions between him and the bullet?
Oct 17 '12 at 12:42 PM
masabusharif
You don't need a call from a collision or entry of a trigger to detect if something is within the bounds of the object. Just check if the distance is short enough, or use a raycast (the former is a slight bit more complicated, admittedly, but it would be a lot less costly to perform than the latter). And yes, I realize this was posted over a year later... XP
Mar 28 at 01:30 PM
DESTRUKTORR
Its ok, i appreciate your response :), well the solution for what i wanted was checking for distance, and everything went perfectly, thank you
Apr 01 at 08:19 AM
masabusharif
(comments are locked)
|
|
The only code you even have is in the pierce bullet section, and it's a while loop that can never exit. A while loop runs until its condition becomes false and that condition can never be false inside that loop. If you want to use a while loop it either needs to yield or eventually make its condition false: while ( true ) { x++; yield; } while ( x < 10 ) { x++; } Ignore collision prevents collision from happening. The best way to ignore collision between groups of objects is to put their prefabs on different physics layers and then set the project's physics settings so those layers don't collide. Triggers are able to pass through each other without colliding but you need to use OnTriggerEnter instead of OnCollisionEnter. Vincenti: There was no code in the other sections was because it was working fine and I didn't want to type it all.
Jul 31 '12 at 05:34 PM
Niluk93
(comments are locked)
|
