- Home /
Question by
Deathwolf07 · Jul 17, 2014 at 03:24 PM ·
javascriptcollisionrigidbodycollision detection
how to make an Explosive rigidbody trigger by another collision box
I have found a code to make an explosive rigid body but how do I make it trigger when I go through another objects trigger collision box?
var radius = 5.0;
var power = 10.0;
function Start () {
// Applies an explosion force to all nearby rigidbodies
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (hit && hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
}
}
Comment
Research OnTriggerEnter() and OnCollisionEnter(). One will likely be what you want to solve this problem. Lots of posts on UA concerning what is needed to make each work.
Your answer
Follow this Question
Related Questions
How do I "remove/disable" collision? 3 Answers
Car dynamics? 0 Answers
Avoid Player bouncing when colliding with objects 3D 1 Answer
Enemy death help 1 Answer
Different results between "ContactPoint" and "ContactPoint2D" 0 Answers