- Home /
How do I get an explosion force to ignore my character's rigidbody?
I have a 2.5D platformer that I'm working on and I want a mechanic where there's an explosion force applied to everything around my character, but not to my character. It's kind of like a sphere of force that pushes everything around him away. Unfortunately, I haven't been able to stop this force from being applied to my character, so when I hit the button, my character goes flying. So how can I get the ExplosionForce to ignore my character's rigidbody/collider?
// Force Explosion Function
void ForceExplosion() {
Vector3 explosionPos = transform.position;
Collider[] colliders = Physics.OverlapSphere(explosionPos, explosionRadius);
foreach (Collider hit in colliders) {
if(hit.rigidbody != null){
hit.rigidbody.AddExplosionForce(explosionPower, explosionPos, explosionRadius, explosionUpwards);
}
}
}
Answer by schaddemm · Feb 10, 2013 at 02:06 AM
How about:
if(hit.rigidbody && hit.gameObject.tag!="Player") {...}
(code from memory and I might got the syntax wrong, but you get the idea. If not complain and I'll look it up)
Your answer
Follow this Question
Related Questions
ExplosionForce On Instantiated Object 1 Answer
[C#]rigidbody.addExplosionForce,Help? 2 Answers
Detecting the right time to play a landing animation? 2 Answers
Player Pushes Enemies. (That's bad) -Still Unanswered- 1 Answer
Is it possible to get the physics engine to ignore calculating a rigidbody? 1 Answer