|
Earlier today, I asked for help regarding how to avoid collision between two instantiated gameobjects. With my limited understanding on programming, perhaps a question on the general use of it was a bit over my head. Instead, please help me by looking at my code, poor as it may be, and help me with my problem. I need to make Missile and Enemy ignore collision with each other. using System.Collections; public class EnemyBehaviour : MonoBehaviour { } That is for the Enemy using System.Collections; public class MissileBehaviour : MonoBehaviour { } That is for the missile
(comments are locked)
|
|
Unity's physics engine allows you to set a layer for each GameObject. It's also possible to set flags to control which layers will collide with each other. You can read more about this in the Unity manual. If you're spawning with prefabs, you can set the prefab's layer using the inspector. If it's easier in your case, you could also set a bullet's layer right after spawning it, from script. If you only need to ignore collision between two specific colliders -- say, a bullet and the character who shot it -- you can call Maybe this is still more general than you're looking for. Is there some specific part of this process that's giving you trouble? Thank you for answering. Yes, this is still a bit too general for me. I understand that Physics.IgnoreCollision() will do what I need, but the problem is that I don't know how to use it. This might just be me who is a total noob at Unity, but I don't know how to find the collider of the missile I'm shooting. For instance, Physics.IgnoreCollision(missile.collider,enemy.collider); From what I understand, I must first find the GameObject of the missile and the enemy, but since both of them are prefabs, I don't know how to do so. Up until now, whenever I've had to use another GameObject I would manually find it in the script and then find the specific GameObject in my scene. This is not possible to do with instantiated GameObjects however, so how do I find these? TL;DR: How do I find the GameObjects of something instantiated and use said GameObjects collider in Physics.IgnoreCollision()
Jun 15 '12 at 05:13 AM
bobthejuser
that is a question for another thread uyour question has been answered for you and should be marked as answered, on the side note to save you time filling out another question you need to set a var to the game object getComponet collider then use it in the Physics.IgnoreCollision function.
Jun 15 '12 at 05:18 AM
bodec
(comments are locked)
|
