Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Wes 1 · Feb 01, 2011 at 12:13 AM · physicsdistancesphereoverlap

How is OverlapSphere used?

I've only found a few posts about it, but i haven't seen it USED, only declared in a var. var EG colliders = Physics.OverlapSphere( position, 150.0);

So how exactly do you put this to use?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by reissgrant · Feb 01, 2011 at 12:40 AM

This was posted by "Duck" a while back: Click Here

*If your enemies have colliders attached, you can use Physics.OverlapSphere to quickly get your initial list of enemies within a certain radius.

You can then loop through each enemy within this list and determine the relative distance to the player, and apply some level of damage to each enemy within the radius, proportional to its distance.

It would end up looking something like this. It assumes that your enemy objects have both a collider and a script called "Enemy" attached.*

function AreaDamageEnemies(location : Vector3, radius : float , damage : float ) { var objectsInRange : Collider[] = Physics.OverlapSphere(location, radius); for (var col : Collider in objectsInRange) { var enemy : Enemy = col.GetComponent(Enemy); if (enemy != null) { // linear falloff of effect var proximity : float = (location - enemy.transform.position).magnitude; var effect : float = 1 - (proximity / radius);

         enemy.ApplyDamage(damage * effect);
     }
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Jessy · Feb 01, 2011 at 12:41 AM

The potential uses, like for most everything in the Unity API, are infinite.

Let's see what comes off the top of my subconscious...

An enzyme is in a stomach. Check to see if certain proteins are within range of the enzyme. Destroy the colliders for the proteins that overlapped because now they're more gooey and ephemeral, instead of being solid gelatinous globs.

That ship from The Abyss starts rising at the end of the movie. Check the sphere around it, and if any dolphins are within range, have them freak the @$#% out. As in, maybe use Collider.attachedRigidbody along with Rigidbody.AddExplosionForce.

Like the docs say, it's dealing with bounding boxes, so it could result in more useful behavior sometimes, than just checking distances between transform.positions, as distance checks often do.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wes 1 · Feb 01, 2011 at 03:21 PM 0
Share

Haha, thanks for the eye opener but "how it's used" is a bit different then "how to use it" ;) But I might use that advice later for my rising-ship-freak-the-@#$*&-out-dolphin game I've been planning :P

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Physics Overlap Sphere issue 0 Answers

OverlapSphere is really confusing 0 Answers

Is Raycast relatived to screen resolution? 1 Answer

How to use Sphere colliders to detect the "Player" 1 Answer

Collision between player and a ball 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges