I want to test for collisions between a bomb detonating in a circle/ sphere and a player. I want the player to be safe if standing behind a gameobject shielding him from the blast. What is the most efficient way to do this?
I don't have any code yet. Really just looking for some gentle nudging in the right direction. My initial inclination is to iterate through 360 ray casts each separated by a degree (and that only works for circular and not spherical collision) but I was hoping there was a better way to do this. Is spherecast the appropriate method? Any thoughts would be much appreciated.
Answer by The-Evster · Aug 18, 2016 at 12:49 PM
If the player is in the blast radius then use
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
ShootRayAtPlayer(); //Have this function set up to shoot a raycast in the direction of the player
}
}
This way if there is something between the bomb and the play the raycast wont reach the player and if there is nothing between them just use hit.transform.SendMessage() to apply any damage. Hope this was helpful.
Awesome! This is exactly what I needed. It definitely makes a lot more sense to just use a ray shot at the player ins$$anonymous$$d of in a sphere testing for collisions everywhere. tyty
Your answer
Follow this Question
Related Questions
Doom/Wolfenstein 3D-style targeting system. Detect enemies in camera view? 0 Answers
SphereCastAll hit.point are allways zero 1 Answer
Stubborn Pick Up Script 0 Answers
how to do sphere cast 0 Answers
Physic SphereCast hits null 1 Answer