- Home /
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[i] = Instantiate(replacement[y], transform.position, transform.rotation);
replacementSpawn[i].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.
Answer by nsxdavid · Mar 18, 2013 at 05:32 AM
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.
Im not sure moving the functionality to the parent will work because each collision is a turret with a separate turret mesh. So they can be destroyed separately.
I tried giving each turret a rigidbody and they worked but then they acted like they weren't a child to the parent object anymore because they stayed inplace while the parent followed the waypoints.
Also what i am try to achieve is in my question asa comment, "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."
Your answer
Follow this Question
Related Questions
Player colliding with pickable object 0 Answers
Transform collider not detecting collision on rigidbody collider 2 Answers
100 OnTriggerEnter Or Tags each player too much? 3 Answers
Child calling parent's OnTriggerEnter when no Rigidbody is attached to child 1 Answer
OnTriggerEnter not working, tried everything! :( (C#) 3 Answers