Hi,
I am struggeling on how to apply damage and force by the distance from the center of the explosion.
The distance of each founded collider is converted to a ratio, with 0 being at the edge of the explosion radius / away from the explosion center and 1 at the explosion center. The applied force and damage should be multiplied with that value, but I am doing wrong calculations.
This is the OnCollisionEnter function of the Proximity Mine:
void OnCollisionEnter(Collision hit){
Collider[] col = Physics.OverlapSphere(transform.position, explosionRadius, detectionLayer);
foreach(Collider c in col){
float dist = Vector3.Distance(transform.position, c.transform.position);
float ratio = 0;
ratio = Mathf.InverseLerp(explosionRadius, dist, ratio);
if(c.gameObject.layer != LayerMask.NameToLayer("Projectile")){
c.transform.SendMessage("ReceiveDamage", damage*ratio);
c.transform.GetComponent<Rigidbody>().AddExplosionForce(explosionPower*ratio,
c.transform.position, explosionRadius, 30.0F, ForceMode.VelocityChange);
}
}
}