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
1
Question by Patyrn · Feb 25, 2011 at 01:07 AM · javascriptarrayoverlapsphere

Physics.OverlapSphere with a min radius?

So I'm trying to detect things within x radius and without y radius. A donut shaped area of detection. My plan is to use two OverlapSpheres and remove colliders from the small one from the collection the large one returns.

Is this the best way to do this? If it is, what's the best way to filter an array like that? There don't seem to be any helper functions like Array.Without.

Comment
Add comment · Show 2
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 cregox · Feb 28, 2011 at 03:48 PM 1
Share

just a hint (maybe)... ins$$anonymous$$d of calling it "x radius" and "y radius" it could be better to call 'em "`a` radius" and "`b` radius". small detail, but I think it generates lot less confusion while reading because x and y look like axis coordinates.

avatar image Patyrn · Feb 28, 2011 at 06:17 PM 0
Share

Probably a good idea.

1 Reply

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

Answer by Bunny83 · Feb 25, 2011 at 01:30 AM

Well that's quite simple:

// C# and needs using System.Collections.Generic;
public static List<Collider> GetDonut(Vector3 pos, float InnerRadius, float OuterRadius)
{
    List<Collider> outer = new List<Collider>(Physics.OverlapSphere(pos,OuterRadius));
    Collider[] inner = Physics.OverlapSphere(pos,InnerRadius);
    foreach (Collider C in inner)
       outer.Remove(C);
    return outer;
}

EDIT
Here the JS version:

function GetDonut(pos : Vector3,InnerRadius : float, OuterRadius : float) : List.<Collider>
{
    var outer : List.<Collider> = new List.<Collider>(Physics.OverlapSphere(pos,OuterRadius));
    var inner : Collider[] = Physics.OverlapSphere(pos,InnerRadius);
    for (var C : Collider in inner)
       outer.Remove(C);
    return outer;
}

Well, the Name is not really good but it's just a sample ;)
This function returns a List<> but with .ToArray() you can convert it back to an array if you really want.

Comment
Add comment · Show 6 · 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 Patyrn · Feb 25, 2011 at 02:22 AM 0
Share

I'm writing in javascript though. JS doesn't have a List collection.

avatar image Bunny83 · Feb 25, 2011 at 05:25 AM 0
Share

What? who said that? If you would talk about JScript you might know from websites you're right, but UnityScript is a totally different language. It compiles also on the mono platform like C#. The greatest differences between C# and UnityScript is the syntax. JScript also don't support inheritance (it use prototypes) but in Unity it does. In the end you can do quite everything in both languages but in JS it's often the longer way and not as "save" as C#.

avatar image Herman-Tulleken · Feb 25, 2011 at 07:32 AM 0
Share

Is this not a spherical shell ins$$anonymous$$d of a donut shape?

avatar image Bunny83 · Feb 25, 2011 at 10:56 AM 0
Share

Sure :D but he described it as donut. If you really want some kind of a donut shape (only a kind of) just use this function from a OnTriggerEnter Event of a box collider that specifies the "cut-out" area. If you just need it global axis-aligned flat on the floor you can check the relative y from the center and exclude all that lays outside. As I said it's just a volume that have the general form of a donut but it isn't

avatar image cregox · Feb 28, 2011 at 03:59 PM 1
Share

@Patyrn you could have your C# file separated and still use that function within your JS code: http://answers.unity3d.com/questions/21676/is-it-possible-for-c-script-using-class-written-in-js

Show more comments

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

Possible to use an array value as the name of a variable? 2 Answers

CompareTag and OverlapSphere 1 Answer

Make an array containting multiple classes 1 Answer

expected. Insert a semicolon at the end. When the end that it says, is a } Could someone help us fix this? 2 Answers

have array target person of most priority/stick with top prior 0 Answers


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