Waypoint Question(Conflicting Collision)

I found a waypoint script on this awnsers site that Im sure everyone is familiar with(and altered it a bit):

var waypoints : GameObject[];
var speed : float = 3;
public var currentWaypoint : int;


function Start()
{
	waypoints = GameObject.FindGameObjectsWithTag("BossWaypoints");
}

function Update () 
{
	if(currentWaypoint < waypoints.length)
	{
		 var target : Vector3 = waypoints[currentWaypoint].transform.position;
		 var moveDirection : Vector3 = target - transform.position;
		 var velocity = rigidbody.velocity;
		 
		if(Vector3.Distance(transform.position, waypoints[currentWaypoint].transform.position) < 50 )
		{
		 	currentWaypoint++;
		}
		else
		{
			velocity = moveDirection.normalized*speed;
		}
		rigidbody.velocity = velocity;
	}
	else
	{
		currentWaypoint = 0;
	}
	
}

But my question lies with the rigidbody that is required for this script to work. When I have a rigidbody attached to the parent object(which also holds this script), the child objects’ collision under it doesn’t recieve damage or allow the OntriggerEnter to activate. How do I get the function for the child to work if the rigidbody is stopping it? This is the script that is on the child along with the collision:

var hp : float;
var replacementSpawn : GameObject[];
var replacement : GameObject[];
var scoreAmount : int = 0;
var scoreHolder : GameObject;
var turretReplacement : Transform;
var turretMaterial : Material;
var regularTexture : Texture2D;
var changedTexture : Texture2D;

function Start()
{
	turretMaterial.mainTexture = regularTexture;
}

function OnCollisionEnter(collision : Collision)
{
	turretMaterial.mainTexture = changedTexture;
	yield WaitForSeconds(0.1);
	turretMaterial.mainTexture = regularTexture;
}

//Take Damage Function
//Subtract damage from hp

function TakeDamage( damage : float )
{
	hp = hp - damage;
	if(hp <= 0)
	{

		var i : float = 0;
		
		while( i < replacementSpawn.Length)
		{
			var y : float = 0;
			while( y < replacement.Length)
			{
				replacementSpawn *= Instantiate(replacement[y], transform.position, transform.rotation);*

_ replacementSpawn*.transform.parent = turretReplacement;_
_
y++;*_

* }*
* i++;*
* }*
* scoreHolder = gameObject.Find(“ScoreText”);*
* scoreHolder.SendMessage(“ScorePoints”, scoreAmount );*
* SendMessage(“Die”, SendMessageOptions.DontRequireReceiver);*
* Destroy(gameObject);*
* }*

}

Can anyone help me with this? What I am trying to do is move my enemy Boss back and fourth between two points and it works, but because I have a rigidbody attached to allow the script to work, the turrets' collision on the boss that are children to the mesh don't receive damage or the OnCollisionEnter that I have doesn't register either. Its because of the rigidbody, I tested each component and thats what does it.

1 Answer

1

All child object’s that have colliders report their collision events to the class wit hthe rigidbody. This is expected behavior. In this way you can create a complex collision shape from many child colliders.

One answer would be to move the functionality to the parent object’s script. But it all depends on what you are after.