- Home /
Question by
Ambrose998800 · Nov 16, 2019 at 02:56 PM ·
forceexplosionradius
Physics.OverlapSphere wrong radius
For my asteroid-fighter game, I have exploding asteroids that are triggered by a Physics.OverlapSphere check. The radius for that is '5' in this case.
Problem is, the radius for the check doesn't work at all (the green collidersphere around the ship at the impact point is already 250 units in radius):
Here is the Code I use (the explosion is called by the ship-script at destruction):
void DestroyShip()
{
print("Enemy ship was destroyed after " + TimeSurvived + " seconds");
Sp.ExplosionTemplate(transform, ExplosionForce, 5, false, "FractureAsteroid", "");
GetComponent<Renderer>().enabled = false;
Rb.isKinematic = true;
if (ShipExplosionEffect != null)
{
ParticleSystemScript ExplosionScript = ShipExplosionEffect.GetComponent<ParticleSystemScript>();
ShipExplosionEffect.transform.SetParent(transform.parent);
ExplosionScript.RunParticleSystemOnce = true;
ExplosionScript.DestroyWhenFinished = true;
}
Invoke("AfterBlast", 1.5f);
}
Masterscript ("Sp." in ship-script):
public void ExplosionTemplate(Transform Charge, float Force, float Radius, bool AffectsNonAsteroids, string HitMessage, string HitMessageParameter)
{
Collider[] Colliders = Physics.OverlapSphere(Charge.position, Radius);
foreach (Collider Hit in Colliders)
{
Rigidbody Rb = Hit.GetComponent<Rigidbody>();
if (Hit.GetComponent<Asteroids>())
{
Rb.AddExplosionForce(Force, Charge.position, Radius);
if (AllowBuildingClusters)
{
Hit.gameObject.SendMessage("RipConnection", SendMessageOptions.DontRequireReceiver);
}
}
else
{
if (Rb != null && AffectsNonAsteroids)
{
Rb.AddExplosionForce(Force, Charge.position, Radius);
}
}
if (HitMessage != "")
{
Hit.gameObject.SendMessage(HitMessage, HitMessageParameter, SendMessageOptions.DontRequireReceiver);
}
}
}
unityexplosionrangeissue.jpg
(186.5 kB)
Comment
Your answer
Follow this Question
Related Questions
Adding explosion force knockback on player 1 Answer
Make grenade apply force to rigidbodies around it 3 Answers
Add Explosive Force - Coins 1 Answer
ExplosiveForce Strange effects. 1 Answer