Hi - So I’ve got a simple game set up in which objects are spawned at different locations for collection. I also have an enemy that is patrolling the perimeter. The enemy has a controller, and a sub-object with a collider, which was set up to allow it to cause damage to the character if it comes in contact. However, I want the enemy to ignore collisions with the spawned objects (just pass through them), but my code doesn’t seem to be working. From the awake function, I call this:
var enemyRef: GameObject; //drag the gameobject into the inspector that is the enemy
function Awake()
{
for (var j:int = 0; j < numberOfPickups; j++)
{
SpawnPickup();
}
}
function SpawnPickup(){
// instantiate (create) the pickup prefab with the above position and rotation
var spawnedPickup:GameObject = Instantiate(pickupPrefab, spawnedPickupPosition, spawnedPickupRotation);
Physics.IgnoreCollision( spawnedPickup.collider, enemyRef.collider); //TODO: Get enemy to ignore spawnedPickups
}
Is it not working because it needs to be continually detected? Is it because I have a game object with a collider as a child of a game object with a controller? Thanks for any help you can provide.