- Home /
problems with dead replacement of the damage reciever???
hey guys i have a damage reciever added on my shield my shield is a child of the first person players Graphics gameobject that works fine now but my dead replacement object isnt a child of the graphics gameobject. and it must become a child of the graphics gameobjecthow do i do that here is the damage reciever script
var hitPoints = 100.0; var detonationDelay = 0.0; var explosion : Transform; var deadReplacement : Rigidbody;
function ApplyDamage (damage : float) { // We already have less than 0 hitpoints, maybe we got killed already? if (hitPoints <= 0.0) return;
hitPoints -= damage;
if (hitPoints <= 0.0) {
// Start emitting particles
var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
if (emitter)
emitter.emit = true;
Invoke("DelayedDetonate", detonationDelay);
}
}
function DelayedDetonate () { BroadcastMessage ("Detonate"); }
function Detonate () { // Destroy ourselves Destroy(gameObject);
// Create the explosion
if (explosion)
Instantiate (explosion, transform.position, transform.rotation);
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
// If there is a particle emitter stop emitting and detach so it doesnt get destroyed
// right away
var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
if (emitter) {
emitter.emit = false;
emitter.transform.parent = null;
}
}
// We require the barrel to be a rigidbody, so that it can do nice physics @script RequireComponent (Rigidbody)
Please help
Answer by Antony-Blackett · May 09, 2011 at 09:28 PM
dead.gameObject.transform.parent = transform;
i have made this but it doesnt work
private var parent : parent; var dead : GameObject;
function Update () { dead.gameObject.transform.parent = transform; }
You put that line right after the deadReplacement Instantiate call. You only have to set the parent once.
You can see in the scene view if your new object is indeed a child of what you want to be the parent. I think you may be running into trouble because your child has a rigidbody which will simulate in the physics simulator and not keep it's relative position to its parent.
Your answer
Follow this Question
Related Questions
Damage Reciever Won't Destroy Object 1 Answer
How to add terrain destruction 1 Answer
Player Health Damage 2 Answers
Bootcamp damage 0 Answers
standing in fire or specific area I wanna take damage 1 Answer