OnTriggerEnter and spawning gameObjects

Hi All,

I am having trouble with the following:
I have a small army of 100 soldiers. The player can cast a shield on top of those soldiers. The shield is a big sphere that when entered, sends the troops a message that they are shielded. On Exit the shield sends the soldiers the opposite message. It works fine for one thing. If the soldiers are stationary and I spawn the shield, the collision is not detected. If I then move the soldiers, it is detected. I tried scaling the shield, but that the problem stays the same. Same thing when the shield shrinks: the collision is not detected when the soldiers are stationary. Is there any way to fix this? I have included the code on the shield.

//this script handles the effects of the AoE shield
private var shrink : boolean;

function Start () 
{
	yield WaitForSeconds(5);
	shrink = true;
	Destroy(this.gameObject, 3);
}

function Update()
{
	
	if(transform.localScale != Vector3(100, 100, 100)  !shrink)
	{
		transform.localScale = Vector3.Lerp(transform.localScale, Vector3(100, 100, 100) ,Time.deltaTime);
	}

	if(shrink)
	{
		transform.localScale = Vector3.Lerp(transform.localScale, Vector3(0,0,0),Time.deltaTime*2);
	}
}
function OnTriggerEnter(other : Collider)
{
	if(other.tag == "Soldier")
	{
		other.GetComponent(troopScript).ActivateAOEShield();
		
	}
}

function OnTriggerExit(other : Collider)
{
	if(other.tag == "Soldier")
	{
		other.GetComponent(troopScript).DeactivateAOEShield();
	}
}

Have you tried OnTriggerStay ?

You could try to cast a physics sphere-cast to those in the sphere every couple of seconds to save on performance. This will allow you to get to those inside the trigger as an alt to OnTriggerStay.

Thanks for the answer. I could do a OnTriggerStay, but wouldn’t that give me the same problem? The trigger isn’t registered until the soldier moves. I am not sure what you mean by “a physics sphere-cast”. Could you elaborate?