Hello,
I’m trying to put together a zombie game where I must headshot the zombies to kill them. I have an animated character mesh with attached character controller component. On a prototype, I had the zombie as a head and body object where the head could be shot and send a kill message to the body. On this version, however, if I try to add another collider near the head the zombie starts looking as though it is breakdancing.
My question is, is there any way to have the zombie damage script locate the position of raycast hits along the zombie’s character controller so I can simulate a “headshot”? Here is my script:
var hitPoints = 100.0;
var damage = 5.0;
var damageHeight = 3.0;
var detonationDelay = 0.0;
var explosion : Transform;
var deadReplacement : Rigidbody;
var deathsound : AudioClip;
function Headshot (Raycast : Collision) {
var hit : RaycastHit;
if (Physics.Raycast (hit.point.position.y >= damageHeight)) {
SendMessageUpwards("ZombieDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
function ZombieDamage (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;
}
}
Keep in mind that I am not myself a coder but lean more towards the artist side. Please respond with specific code examples if possible. Thanks