x


trigger and colliders not detecting properly

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 gravatar image

Diet Chugg
277 23 28 36

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 gravatar image

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
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1765
x1018
x181

asked: Nov 08 '10 at 11:16 PM

Seen: 1120 times

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