- Home /
How do I ignore collision between two instantiated objects.
Okay, I know there are a lot of variations of this question already out there, but none of them helps me and searching through every single one for the one right answer would take forever.
I have certain questions regarding Physics.IgnoreCollision
1) How do I use Physics.IgnoreCollision?
From my understanding I have to use the names of two gameobjects, but this is clearly wrong since I wouldn't be asking otherwise.
2) How do I get transform values from instantiated objects?
I often find that I have several clones of an object which is not in the scene, but I have no idea how to get their transform values. If I try to get the transform of the original it often returns nothing.
3) In the Physics.IgnoreCollision reference it says
Transform bullet = Instantiate(bulletPrefab) as Transform;
What exactly is happening here?
Answer by whydoidoit · Jun 14, 2012 at 01:14 PM
1) You need to pass two colliders to IgnoreCollision - you would get those colliders from the GameObjects/Transforms or whatever you have to reference them.
2) When you instantiate an object from a prefab you get a return value which is the new object, as whatever type your prefab holder was. So if you hold prefabs in GameObject variables you would do this:
var newGo = Instantiate(someGameObjectPrefab) as GameObject; //c#
var newGo : GameObject = Instantiate(someGameObjectPrefab); //JS
And if you want the transform you get it like this:
newGo.transform
You would get the collider for newGo by using newGo.collider
3) It is creating a new bullet, the prefab for it is held in bulletPrefab which is a Transform variable.