# trigger and colliders not detecting properly

 0 Hi I have a bomb that when explodes creates an explosion trigger object that deals damage to the player if they collide or trigger with the object. I have tried using OnTriggerStay and OnCollisionStay but I have found a problem with these: when the explosion is created at the same point as my character is at and my character is not moving the Collider or Trigger does not take effect. However if my player moves into the trigger or moves within it. Than the trigger takes effect. How can I fix this? more ▼ asked Nov 08 '10 at 11:16 PM Diet Chugg 277 ● 23 ● 28 ● 36 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 Don't depend on collision. Use a raycast or if using a sphere, the distance (squared if you really want to be efficient), and determine if your player is within the collider. more ▼ answered Nov 08 '10 at 11:52 PM skovacs1 10k ● 11 ● 25 ● 92 sounds like a good idea. how would I check to see how close the closest object of explosion is to the player? Nov 09 '10 at 12:43 AM Diet Chugg The answer was more general than that. When the explosion starts (and if you've got a lengthy explosion, in Update, during the explosion), you would check if the player is alive and is inside and apply damage. It's not really about finding the closest explosion. If you need to know that, then you'd probably want to maintain a list of active explosions and you would check each one of them. Nov 09 '10 at 03:08 PM skovacs1 You would still want to check as little as possible. To check the readius, in your explosion, you could call Collider.Raycast on the explosion's collider from the player position to the explosion and if it doesn't hit, then you're inside the explosion. Alternatively, still in the explosion you would do something like (player.position-explosion.position).sqrMagnitude or .magnitude or you could even call Vector3.Distance and if the result is less than some amount, your player is inside the radius. If you really aren't too picky, you could even use Physics.OverlapSphere. Nov 09 '10 at 03:12 PM skovacs1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1765
x1018
x181

asked: Nov 08 '10 at 11:16 PM

Seen: 1120 times

Last Updated: Nov 08 '10 at 11:16 PM