- Home /
getting the radius/position of overlapsphere
Hey guys, noob question, but i applied an overlap sphere using add componenet. When writing my collision detection code, how do I get the radius and center I applied?
Collider[] cols = Physics.OverlapSphere(center, radius);
I have this so far, but it doesnt recognize the "center" and "radius" from when I added the component.
Answer by Owen-Reynolds · Apr 20, 2014 at 06:11 AM
You're probably confusing a Sphere Collider with OverlapSphere. A Collider component automatically checks for hitting stuff. And, when it does, it knows to run whatever code you put in OnCollisionEnter. It's the more common.
OverlapSphere isn't a component. It's a 100% programmed way to "flash" a temp collision sphere. The center and radius are whatever math you feel like putting there. It's mostly used for special 1-time detection. Like to see who's hit by an explosion.
Answer by Sisso · Apr 20, 2014 at 01:56 AM
It is a static method, there is no way to know which object called. So, center is defined as world coordinates.
Use something like:
Physics.OverlapSphere(transform.position + center, radius);
Your answer
Follow this Question
Related Questions
Detect collider collision ,identify and access colliding colliders 0 Answers
Rigidbody necessary to use collision detection 1 Answer
Rigidbody necessary to use collision detection 0 Answers
overlapsphere to destroy NPCs on exit 1 Answer
OverlapSphere, check how many object with specific tag did it collide with.. 2 Answers