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 Sparty · Sep 22, 2015 at 03:48 PM · raycasttriggerraycastingmesh collider

Mesh Colliders as triggers not working... Work-arounds (raycast)?

Hey Gang, I am playing around with a new game concept and need a bit of help getting it off the ground.

My game has thousands of cut out pieces of geo. Some concave, some convex. Each piece of geo is white. Once the player passes over it (triggers it), color is turned on via a script. I have this working (as you can see in the video below), by attaching a sphere collider to each piece of geo.

Here is a little video of what I have so far using sphere colliders. https://youtu.be/tdETeN12ON8

The PROBLEM: While using sphere colliders mostly works, there are many times that it simply does not because of the odd shape of the mesh. Placing multiple sphere or cube colliders per each piece of mesh seems out of the question because of the amount of time that would take me. The easiest answer would be to make each piece of mesh a mesh collider with trigger on, but that no longer works in unity 5 because of the latest physics engine. At least, that is what I have read and testing seems to support it. i should probably also mention that all the mesh being used is planar. Perhaps the answer is raycasting, but I am rather unfamiliar with raycasting and have no clue if it would kill performance.

Any suggestions on how I should go about doing this? It will be on a massive scale, so I really want to hammer down a clean way of doing it and am open to any suggestions.

Thanks all!

-Eric

Comment
Add comment · Show 4
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 Cherno · Sep 22, 2015 at 06:30 PM 0
Share

Have you tried using compound colliders? $$anonymous$$ultiple mesh colliders on the same concave object which are individually convex so they can be triggers.

avatar image Sparty Cherno · Sep 22, 2015 at 06:57 PM 0
Share

I have looked into this option as well. But, as I understand it, it would take a lot of manual placement of colliders. Which I don't see being able to do considering the game will have literally hundreds of thousands of collider triggers.

avatar image Cherno Sparty · Sep 23, 2015 at 09:25 AM 0
Share

For what it's worth, there is at least one asset on the asset store that automatically creates compound colliders.

avatar image Sparty · Sep 24, 2015 at 12:11 PM 0
Share

I don't see the comment any more, but someone asked....

"Is your desired end result to have very precise detection when the player is overlapping the geometry?".

The answer would be no. Precise is a bit strong. I just want something sort of close. An example right now would be, I have a sphere collider trigger on a banana shaped geo, and that simply doesn't work. I am aware that I could go in by hand and create three colliders to get me a banana'ish shape, and use that. But doing that on this scale just isn't feasible with how many times I will have to do this.

-Eric

3 Replies

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

Answer by Key_Less · Sep 22, 2015 at 11:59 PM

This seems like a very fun problem to solve and I have a couple links here that I think may help you. Take a look at this and this.

I haven't done much research on this, but if I were to attempt this issue I feel like I would start with the Separating Axis Theorem (SAT). From there I would try to improve performance by giving the player a radius check where the SAT algorithm is only applied to geometry that is within a specified distance of the player, and only geometry that hasn't already been overlapped by the player.

Hopefully these can help get the gears turning upstairs, I'd be curious to know what you come up with!

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 Sparty · Sep 23, 2015 at 03:54 AM 0
Share

It is a fun one! I think it'll be quite rewarding if i can figure it out. I'm just wrapping my head around these links. Pretty scare stuff for a novice programmer. If i am understanding the gist, basically, these work in the player finding the outer edge of the mesh? Which would be perfect.

avatar image
0

Answer by Hronet · Sep 22, 2015 at 08:46 PM

So my understanding is that you're currently using alternative colliders because that way at least it "works" and in this case it seems to be sphere to sphere collision?

I think you're afraid of using polygon colliders because of the overhead with checking complex shapes for collision (which you're totally justified in being hesitant of.)

I believe your best bet would be to use binary space partitioning in conjunction with polygon (or rather, mesh) colliders. In layman's terms, the binary space partitioning would let the player and objects in the scene know which 'quadrant(s)' (although that's a bad term here because there will be more than 4 subsections) that object was in. Once in there it will only detect collision with objects also in that space. This system will make it so your objects won't even both checking collision with each other if they aren't even in the same neighborhood, and this won't even be an if check, it'd be very direct.

The difference is like foreach( var obj in AllObjectsInScene ) obj.CheckCollision( Player ); and foreach( var obj in Cell[Player.x][Player.y][Player.z] ) obj.CheckCollision( Player );

I don't know if Unity inherently supports it, but I think it would help if you were able to get it.

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
0

Answer by iovergard · Nov 06, 2016 at 10:12 PM

Hi there, I ran into a similar problem and I solved it by creating an editor component that can decompose a concave mesh into a set of convex meshes which can be used as triggers. You can see and use the code on github

I'm not sure if there's a better way to do this besides solid leaf bsp trees, but that's the one I knew and it seems to be working pretty well for me.

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

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

6 People are following this question.

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

Related Questions

How do I have the object disappear once the FPS controller looks at and then looks away. 0 Answers

Can RaycastHit2D.point be inside a BoxCollider2D if raycast was performed from outside that collider? 1 Answer

Raycast exit point of collider 0 Answers

Raycasting doesn't hit terrains 0 Answers

What's wrong with my RayCastHit2D? 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