|
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?
(comments are locked)
|
|
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. 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)
|
