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 POiD · Feb 28, 2015 at 06:28 AM · collisionphysicscollision detectionedge

How do I solve the Box Collider (3D) Edge / Corner Collisions problem?

I posted a similar question in the unity forums 10 days ago and haven't had any responses at this point.

http://forum.unity3d.com/threads/box-collider-3d-collisions-corner-collisions-edge-collision-issue.298752/

In short my level is made up of box colliders (3D). My player (and other objects) are using non-rotating Box Colliders (3D). I'm not sure how to solve my issue with Unity Physics when the player or other objects hit the 'edge' of a Box Collider, even though it is next to another box collider and needs to act as if it's 1 object.

I am already combining as many Box Colliders together as possible into 1, but there are instances I cannot avoid where this will still occur.

I'd prefer to use Unity to detect collisions as from what I've read PhysX is extremely optimized. Is it possible or will I have to check for collisions using Ray Casts every FixedUpdate() on my moving GameObjects and reflect their velocities appropriately, thus not benefitting from PhysX?

Are there other options / solutions I can look at?

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

5 Replies

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

Answer by AlwaysSunny · Feb 28, 2015 at 06:28 AM

I've never faced this particular dilemma, but I know a teeny bit about the physics system's many quirks. Unfortunately, the issue(s) you seem to be describing are inherent nuances of the physics sim. Someone correct me if I'm wrong. Just as floating point precision is finite, so too is the simulation accuracy.

I'm confused by your stated requirements, such as the non-rotating box collider for the player. Using a non-rotating sphere collider of the same diameter might (probably would!) mitigate these issues a great deal. Also, proper masses, forces, frictions, and bounce factors go a long way to polishing the sim.

It's perfectly fine, by the way, to blend your behaviors among raycasting, triggers, and actual collision reactions. Any quality, robust simulation has some extra sensors and actuators working unbeknownst to the player! As long as your physics equations are sound and your various sensors and actuators are sufficiently competent, it can all work really well.

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 POiD · Mar 02, 2015 at 01:16 PM 0
Share

Thanks for the response.

I'm using a non-rotating Box Collider ins$$anonymous$$d of a sphere because I need to emulate the same collisions as the old game client I'm recreating, and it used box colliders. For testing purposes I did try with a Sphere and do encounter the edge bounce back issue even with a sphere unfortunately. :/

As far as the extra ray-casts, I'm assu$$anonymous$$g the best place for these is in FixedUpdate(), even though it means a $$anonymous$$imum of 6 rays per FixedUpdate to check for collisions?

avatar image AlwaysSunny · Mar 02, 2015 at 08:27 PM 0
Share

Well, my suggestion wasn't to replace collisions with raycasts; rather to use raycasts as sensors to drive an avoidance behavior or force adjustment. (If wall is N units to left, reduce applied force in -X direction). This may or may not produce results you desire. Physics-driven games are super finicky and require a lot of tinkering to nail down.

Yes, having 6 raycasts per-actor per-frame represents a slight performance drain, but only if you have a ton of actors, and/or are targeting mobile. But as the saying goes, first make it work, then make it work well.

Note that many factors can impact physics performance, and knowing which quirk is responsible for your troubles is a matter of testing and familiarity with the physics sim. Friction and bounce are very important for "sliding" behavior, for instance.

Ultimately, you may need to go so far as to generate a mesh collider which encompasses each of your "islands" or obstacles. Been there, done that. $$anonymous$$ajor headache, but it can be done and made performant.

I recall a situation where my actors were spheres and my obstacles were cubes, and I could get "perfect" sliding behavior along these walls-of-cubes. I don't recall there being a specific problem to overcome (as you describe) - just a lot of tinkering and dialing in the right combination of factors.

The next thing that comes to $$anonymous$$d is, perhaps the simulation is reacting this way because your cuboid actor cannot turn. When it hits these problem areas, perhaps an imperceptible change in rotation would occur, but since it can't, a perceptible hiccup in position occurs ins$$anonymous$$d.

$$anonymous$$y best advice involves changing the properties of your physical objects. You could also try reducing the physics timestep and "skin depth" or whatever Unity calls it for increased accuracy, or changing the scale of the whole project (bigger if it's small, smaller if it's big) such that your physics objects are of a size the physics sim is designed to handle well.

For perspective, in a FPS, a human should be around 2 units high. In a space game, an average ship should probably be around 2 units long, to retain the "accuracy by volume" the simulation was designed around.

Someone correct me if I'm wrong about any of this.

avatar image AlwaysSunny · Mar 02, 2015 at 08:46 PM 0
Share

"$$anonymous$$in Penetration For Penalty" is the "skin depth" thing I mentioned. If your cube objects are so close that they're visibly touching, the skins of two adjacent colliders may overlap. Colliding with this overlap may cause this issue. That might be the source of your problem right there. Try fiddling with this value (in project's physics settings). Or, try setting your colliders to be slightly smaller than 1x1x1.

avatar image POiD · Mar 17, 2015 at 11:21 AM 0
Share

Thanks for the suggestions. I had already messed with the physics time step and the $$anonymous$$ penetration option. I'll try slightly adjusting that one a bit to see what I can get.

Otherwise I was just trying to figure out if it's better for me to change my wall collisions into just triggers and then deter$$anonymous$$ing how to adjust the colliding objects myself (thus getting an exact match on the existing game physics I'm trying to emulate). Or if I do the raycasting to catch only the specific corner hit issue. Using triggers may be better as I don't need as many raycasts each frame, just when I get a trigger collision, but I haven't figured that out yet. Still doing research to find out the best way. :)

Note I'm accepting your answer as it's been the best help so far!

avatar image
9

Answer by AlienFreak · Apr 07, 2016 at 06:53 AM

Edit->Project Settings->Physics Inspector will show PhysicsManager Set 'Default Contact Offset' from 0.01 to 0.001 (I use 0.0001)

This WILL fix it as I use a ton of cubes in a 3D cubic tile based world.

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 DreamEnder · May 02, 2016 at 09:03 PM 0
Share

Doesn't work for my $$anonymous$$i golf game :(

avatar image Roastbeef · Sep 08, 2016 at 04:31 PM 1
Share

Thanks a lot! This solved the problem I had with my tile based, ball rolling game :D

avatar image
1

Answer by venhip · Mar 02, 2015 at 09:12 PM

Hey,

I know this problem well and I'm working on a 2D game, currently. While I'm not using 3D collisions, my solution may help point you in the right direction. I ended up having to use the 'Edge Collider 2D' on my player, rather than the box collider. With each side covered by its own edge collider I've found that I don't get the... sticking to the corner of a block on the floor or walls. It also lets your character's feet have a different physics material to your character's sides.

Good luck

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 POiD · Mar 17, 2015 at 11:22 AM 0
Share

Thanks Venhip. I had read about that option, but unfortunately cannot apply it to my situation due to not doing just a 2D game. Thanks anyhow!

avatar image
0

Answer by ComputerCables · May 15, 2018 at 10:50 PM

I had a similar problem, for anyone who still needs help, my solution was to use box renderers with children quad colliders along the surfaces you want to collide with. even though the edges are flush and shouldn't collide, they do. By excluding these surfaces, the object will never wrongly catch on them.

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 Cloky · Sep 26, 2019 at 01:31 PM

For everyone who still has this problem (I was searching for a solution for ~1hr):

what @AlwaysSunny stated is a great way to deal with this (in most cases). Try to have a gap of e.g. 0,01 between your (box-)colliders, so they don't directly touch each other - your character will not glitch through the edges anymore.

Also, keep in mind that the speed of your character has an influence on the clipping.

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

10 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

Related Questions

OnCollisionEnter isnt called when player lands on object 1 Answer

More accurate collision detection 1 Answer

Physics Collision Layer Programmatically. 0 Answers

Broadphase CD in Unity - pile of rigid bodies unsolved 0 Answers

BoxCollider get stuck when dragging over the border of two BoxColliders 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