- Home /
Problem with AddExplosionForce / Exploding
I have a simple explosion script, but i have a problem. The problem is when exploding, my player always thrown with Y axes or thrown to upwards. I want to make the player always thrown with Z axes or thrown aside. This my simple explode script :
void Start ()
{
Vector3 explosionPos = transform.position;
Collider[] colliders = Physics.OverlapSphere (explosionPos, radius);
foreach (Collider hit in colliders)
{
Rigidbody rb = hit.GetComponent<Rigidbody> ();
if (rb != null)
rb.AddExplosionForce (power, explosionPos, radius, 2f);
}
}
Answer by cbjunior · Jun 13, 2016 at 01:13 PM
The problem is most likely either the exact location of the explosion is too low to the ground or the upwards modifier you are applying. Try either moving the center of the explosion higher or changing your call to the following:
rb.AddExplosionForce(power, explosionPos, radius);
The 2f in your method call is the parameter upwardsModifier which causes the explosion to push bodies upwards. It defaults to zero, so simply remove it from the method call and it should most likely fix your problem.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Moving player along path? 1 Answer
Problem with player movements 1 Answer
Rotating a player object without rotating the axis 0 Answers