|
Hello I am trying to make a projectile, which destroys itself upon impact. The problem is ,i need it to ignore some objects ,such as the character controllers collider, and i am flummoxed why it wont work. My solution is: Also i have been fiddling with Physics.IgnoreCollision ,without results. Maybe it would work with that, and if someone found a way with this ,please explain it troughly, becouse im pretty dense. Any help would be greatly appriciated. Thanks!
(comments are locked)
|
|
Use physics layers if you want to ignore collisions between types of objects. It doesn't require coding and it will be faster as the collision will not take place and therefore no code will be run. Heh, thanks man ,i looked up this layer collision matrix, and it works perfecly! Thanks again.
Mar 11 '12 at 06:49 PM
Sir Mate
(comments are locked)
|
|
I find a bit of issue in your coding. I don't know if that's the cause of the problem. You should use "!=" instead of "!==" . Also, since this script is for projectile, I suggest you use Trigger because Collision sometimes causes slowness to the object. I changed it to != , didnt change a thing. Also, i need colliders ,becouse i want the projectile to influence rigidbodies;which it does, the box goes flying, only it destroys itself upon connecting with and colliders. Thanks for the reply!
Mar 11 '12 at 02:24 PM
Sir Mate
If the change of !== to != did not change anything, it means your problem is somewhere else becuase it should have made a difference. Try to start with only the collison function and destroy and see how it interacts. Then start adding condition until it goe sthe right way. Also, I might be stupid but I don't really get what is happening. Is the projectile exploding or not and whether or not it explodes what is happening to it and around?
Mar 11 '12 at 03:39 PM
fafase
That's strange because I think the code is fine the way it is. Go over what you have done, maybe it gives you some clues. I also find a bit of issue with Unity 3.5 scripting. Some script works fine in 3.4.2 but kinda not working in 3.5.
Mar 11 '12 at 03:41 PM
henry96
!== is not fine. != is fine or == is fine.
Mar 11 '12 at 03:59 PM
fafase
Okay, this is getting ridickolous. I have changed it to "hit.gameObject.layer" , so that it would be easier to determine the problem, so my code is now: function OnCollisionEnter ( hit : Collision){ if (hit.gameObject.layer == "Something" ) { Destroy (gameObject); } } But its working completely ass-backwards! In this case ,nothing destroyes the projectiles, not even the layered objects, whereas if i change it to != than EVERYTHING destroyes them ,again ,even the layered objects. What kind of sorcery is this?
Mar 11 '12 at 04:44 PM
Sir Mate
(comments are locked)
|
