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 /
  • Help Room /
avatar image
1
Question by ThaiCat · Dec 26, 2017 at 10:26 PM · physicscolliderstriggers

Is there a way to filter some colliders out?

I have many objects with box colliders attached to them, each of arbitrary size and position, like on the picture. If i get all the colliders those blue collider collides with, i will get a list that contains all green and red colliders. I want to use blue trigger collider to only store collisions with green colliders. Difference between red and green colliders is that red ones only have a single point where they touch the blue one, or a single line in 3d space.

Is this possible to somehow exclude the red colliders from the list?

Any help is highly appreciated!

alt text

colliders.png (3.2 kB)
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
1

Answer by BOB_KSE · Dec 27, 2017 at 09:52 AM

Its better if you use raycasting instead of boxcolliders.


Its difficult to check where the box collider collision is occuring from and which collider are the ones we need.


Raycasting is better because you can put rays on places where you want to recieve data from, In your case every point except the corners.

Comment
Add comment · Show 4 · 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 ThaiCat · Dec 27, 2017 at 12:32 PM 0
Share

@BOB_$$anonymous$$SE thanks, but there is a problem with raycasting. it has to be some tricky algorithm to deter$$anonymous$$e the points i should perform raycasting from and to. here is an explanation intuitive algorithm 1: raycast from the center of each of the other colliders towards the normal of the other collider side

https://image.ibb.co/fNLAbb/colliders1.png

in this case raycasting from purple collider will not detect blue collider and purple collider will be filtered out as well.

intuitive algorithm 2: perform multiple raycasts from the blue collider with a step less then the $$anonymous$$imal other size of the collider, which for simplicity is a cube with a 1 unit size.

https://image.ibb.co/iSf$$anonymous$$hG/colliders2.png

in this case everything seems to work well, but if a blue collider is a cube size of 30 units, it will require to perform 5400 raycasts (30*30*6 sides), which is also a no go, as it has to be done every frame

edited for better readability

avatar image BOB_KSE ThaiCat · Dec 27, 2017 at 02:38 PM 1
Share

Sorry, but the images you posted in the comment failed to load. so, I can't fully understand what you are trying to say. your rays need to be spaced a little smaller than your 1 unit size block. so that all touching blocks are sensed.

I suggest you watch the first two videos on this playlist. he uses something called as skin width to project the rays from which can be useful in your case. he is making a 2D platformer though.

avatar image ThaiCat BOB_KSE · Dec 27, 2017 at 02:46 PM 0
Share

yep, sorry, i tried to upload new images multiple times, but unfortunately it doesn't work for me anymore too, nor by editing post, nor in comments, (i tried in firefox & chrome) here is direct links to images then

case 1

https://image.ibb.co/fNLAbb/colliders1.png

case 2

https://image.ibb.co/iSf$$anonymous$$hG/colliders2.png

Show more comments
avatar image
1

Answer by BenSan · Dec 27, 2017 at 12:40 PM

You can use several approaches:

  • Disable physics between red and blue objects entirely (by layer) ->https://docs.unity3d.com/Manual/LayerBasedCollision.html

  • You can simply check the collision that you are subscribing to if the tag or layer (or even name, not recommended) is the one you want https://answers.unity.com/questions/261556/how-to-tell-if-my-character-hit-a-collider-of-a-ce.html

  • You can place the red elements with a very small gap, like 0.0001 and make sure they don't collide

  • If you are creating the parts by code you can simply add them to a collection and use that instead (bit out of the scope of this answer)

Comment
Add comment · Show 3 · 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 ThaiCat · Dec 27, 2017 at 01:00 PM 0
Share

im building a ship from all those boxes, all the boxes except the blue one exist, and i dont know which one is red, green or white, i have to deter$$anonymous$$e it, that's the point. They have to be on the same layer, the only object that can be in different layer is the blue one, as it is not built yet

As all the other collider object are a part of the same ship, that belongs to the same player, there is the same issue with the second approach.

I dont quite get the 3rd option, i need o deter$$anonymous$$e neighbor blocks somehow anyway, or the rest of game logic will break

avatar image BenSan ThaiCat · Dec 27, 2017 at 11:10 PM 1
Share

If you are creating the ship procedurally there is no need to get the other parts via collision as this creates an extra overhead anyway. Unless you want to add every part that collides with your ship $$anonymous$$atamari style. When you generate the other parts just add them to the collection wherever you are storing it so you always have a reference.

avatar image ThaiCat BenSan · Dec 28, 2017 at 12:06 AM 0
Share

I don't know what $$anonymous$$atamary style is, but i create ships manually at this point, and they are supposed to be built by players in game, block by block. The reason why i want to filter colliders is to prevent ship design like this:

https://image.ibb.co/f3ByEw/colliders3.png

Right now i use additional compound collider to do the filtering, but it feels like abo$$anonymous$$ation in the code and requires additional work with each prefab. Looks like this:

https://image.ibb.co/isArZw/colliders4.png

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

128 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

Related Questions

Problem With Triggers? 0 Answers

Car will only turn right (& ignored collders) 0 Answers

When Near a door, Press a button to go to the other side. 1 Answer

onTriggerEnter returns wrong object's attribute 1 Answer

How do I detect a collision between two objects using Bolt? 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