Question by
Zastion · Mar 20, 2017 at 03:26 AM ·
scripting problemdamagehealth
How do I make the object apply damage on trigger?
I am trying to make lava damage from a landmine damage script and I am almost there just on problem. when i enter the "lava" it doesn't apply damage right away i have to jump and walk around for it to work. I think the problem is somewhere in this part (var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);) but nothing i have tried makes it work better. any suggestions?
var explosionRadius = 5; var explosionPower = 10.0; var explosionDamage = 100.0; var explosionTimeout = 2.0;
function OnTriggerEnter () {
var explosionPosition = transform.position;
// Apply damage to close by objects first
var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
for (var hit in colliders) {
// Calculate distance from the explosion position to the closest point on the collider
var closestPoint = hit.ClosestPointOnBounds(explosionPosition);
var distance = Vector3.Distance(closestPoint, explosionPosition);
// The hit points we apply fall decrease with distance from the explosion point
var hitPoints = 10;
hitPoints *= explosionDamage;
// Tell the rigidbody or any other script attached to the hit object how much damage is to be applied!
hit.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
hit.SendMessageUpwards("PlayerDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
hit.SendMessageUpwards("Exploasion", hitPoints, SendMessageOptions.DontRequireReceiver);
}
}
Comment