Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 PRINCIEDEV · Feb 17, 2020 at 08:59 AM · gameobjectdetection

How do I detect all gameobjects inside a defined irregular area defined by other gameobjects?

Hi guys, I am making a snake-like game. I have a head and multiple body parts that move similar to slither.io. The movement of snake is also similar to slither.io.

My game mechanic is different, where i encourage players to collide with their own snake body. When they do so, an irregular circle is made. Is there any possible way to obtain the all the game objects within that "irregular circle?"

I am somehow unable to attach a picture, please view the picture here : https://drive.google.com/drive/folders/1WYj6fcnrsFsrddQaxS-jGzrB3QL7uK9P?usp=sharing

Comment
Add comment · Show 1
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 ShadyProductions · Feb 17, 2020 at 09:41 AM 0
Share

You could try to raycast from each bodypart to it's opposite body part (excluding the bodyparts that are not part of the circle (you can check this by adding all body parts from head to the bodypart it collided with to a list and excluded the once left behind). Then you would technically have the entire circle filled with raycast lines, then u can see if any collided with an object. I don't know how performant this would be, just a concept.

1 Reply

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

Answer by Bunny83 · Feb 17, 2020 at 03:26 PM

Yes, just use PolyContainsPoint.


What this actually does is doing is testing each triangle that is formed with the origin if it contains the point or not. Since we toggle the inside state each time we find another triangle we get the proper result. This is the same reason why summing the signed area of all those triangles give you the right surface area. See my gif animations


So if a point falls in a region that is actually outside the polygon, the point would be inside two triangles (one positive, one negative) so it is properly detected as being outside.

I've posted those images in a comment on this question about calculating the area of a polygon.

Comment
Add comment · Show 2 · 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 PRINCIEDEV · Feb 18, 2020 at 10:43 AM 0
Share

Thank you for your idea :) Although it didn't match 100% (because of me not explaining the question properly), it definitely got me in the right direction! For those wondering, What i did was to use all the body game objects to create a mesh (polygon), where i then attached a mesh collider to detect anything inside that polygon!

(This is my fault because I failed to mention that there are multiple objects inside and outside the polygon, which I believe would be more efficient to use the collider ins$$anonymous$$d of checking each object if they are in or out of the polygon (I may have 100+ objects to check!)

Thank you again :)

avatar image AndersonMarquess · Sep 29, 2020 at 12:54 AM 0
Share

This is exactly what i was looking for, i needed to create a abstract area and verify if a given position in world is inside that area and this PolyContainsPoint solve that problem. Thanks for share.

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

192 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WALL collision detection problem... help!!!! 0 Answers

Detection if a GameObject is below you or next to you? 1 Answer

Collision Detection for a Prefab? 3 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Collision Detection When Picking Up GameObjects 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