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 GimLee · Aug 19, 2014 at 08:20 PM · physicsrigidbodyphysics2dboxcollider2d

Unrealistic gap between two objects.

Look at this picture, and please tell me why the upper square wont fall down to the "ground" underneath it. Both are box colliders2D, with the size 1, 1. And they have a rigidbody2D. The upper one have a gravity scale of 5 and a mass of 99, the lower one has is kinematic. Other than that, the rigidbody2d is just standard for both of them.

alt text

gap.jpg (10.0 kB)
Comment
Add comment · Show 6
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 smoggach · Aug 19, 2014 at 08:25 PM 0
Share

Have you tried creating a joint between the two objects?

avatar image GimLee · Aug 19, 2014 at 08:33 PM 0
Share

Smoggach, no. Which one should I use? And this thing happens to ALL my gameobjects that are supposed to fall to this floor.

avatar image smoggach · Aug 19, 2014 at 08:38 PM 0
Share

Try any of them just to see if it will stick them together. Your problem might also have to do with the scale of your world. The object may only think it's resting on the ground because it can't move any lower without going through it. Look up physics scale problems and i'm sure you'll find your answer somewhere.

avatar image GimLee · Aug 19, 2014 at 08:42 PM 0
Share

I now tried with the distance joint. But you see, I need to push the box to the hole to the right. Then the box starts acting all weird when I run into it. Gap is gone between those two now though. But don't think this is the solution to my problem.

avatar image GimLee · Aug 26, 2014 at 08:22 PM 0
Share

Bump!!!!!

Show more comments

4 Replies

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

Answer by kacyesp · Aug 31, 2014 at 04:28 AM

I googled around and apparently someone found a work around that worked for them: http://answers.unity3d.com/questions/609792/2d-collider-arent-exact.html

Apparently if you use edge colliders instead of box colliders, your problem will go away.

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 GimLee · Aug 31, 2014 at 04:51 AM 1
Share

Thanks, I'll try it out right away!

avatar image GimLee · Aug 31, 2014 at 05:03 AM 0
Share

Okay, it seems to help with the gap. But now I just need to figure out why my void OnCollisionEnter2D(Collision2D coll) script doesn't work, after I switched to edge colliders.

avatar image kacyesp · Aug 31, 2014 at 05:09 AM 0
Share

That's because edge colliders have no concept of being entered since they are just edges. Hmm, would it be possible for you to add a slightly smaller box collider than what you had before for your collision functions and leave the edge collider to remove the gap? The reason for using a slightly smaller box collider would be so you don't recreate the gap you removed.

avatar image GimLee · Aug 31, 2014 at 05:34 AM 0
Share

I now tried this. it works after adding the box-collider. But when I change the box-collider size.x to 0.9. It is ignored again. I am making sure the player isn't touching the edge-collider, it is only used for closing the gap.

avatar image GimLee · Aug 31, 2014 at 05:46 AM 1
Share

Don't know why I wrote x, I meant y :D. But sorry about that last comment, I forgot that after my cube suffers from a "fall", its behaviour will change. Changing the size.y caused it to do a tiny "fall". So no problem for now :)

Show more comments
avatar image
2

Answer by sahilshubham · Dec 23, 2019 at 09:48 AM

Ok so here's the correct solution, go to Edit--> Project Settings--> Physics2D, there change the 'Default Contact Offset' value to the least value i.e. 0.0001.

The reason why that gap exists is due to the fact that there is a contact offset set to a value 0.01, which allows to colliders to not contact completely. I just figured it out, hope this helps!

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 $$anonymous$$ · Aug 24, 2020 at 10:57 AM 0
Share

While it's true that it does solve the "unrealistic gaps" reported above, there's another problem your solution creates.

The problem is when you jump and land, the sprite glitches a little through the floor, as if the Rigidbody2D component is set to Discrete and not Continuous.

Are there any other solutions to the issue?

avatar image
0

Answer by superluigi · Aug 19, 2014 at 08:39 PM

It all depends on what you have. Either way it's an easy fix. If those are sprites or textures then what's happening is that they don't take up the whole image. If you used unity's own cube object for those blocks then just shrink the boxCollider2D of the top cube on the Y axis a little. Remember shrink the collider and not the ACTUAL object. After you make it smaller just move the collider upso that the top of the collider matches the cube. 2 easy steps and it's fixed.

Comment
Add comment · Show 9 · 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 GimLee · Aug 19, 2014 at 09:02 PM 0
Share

I can push the block, no problem there. Your answer is what I used to do. Change the boxcollider.Y to 0.969, then it fits perfectly, but it will screw with my player sometimes when he want to jump on top of it. It can't find ground under his feet in some situations. But then you mentioned moving the boxcollider upwards. I tried to change boxcollider2D's center.y to 0.1, but now I can't push the box?

avatar image GimLee · Aug 19, 2014 at 10:07 PM 0
Share

All the pushing is fine, when I don't use joint. I really can't use joints. I just need to fix this gap.

avatar image GimLee · Aug 19, 2014 at 10:08 PM 0
Share

And it is just the standard 2d unity cube

avatar image GimLee · Aug 20, 2014 at 10:42 AM 0
Share

But it isn't I'm sorry. Your answer is what I used to do. But I realized it's not a good fix. The character's y-position will be smaller than it should be when he is walking over it after pushing it down.

avatar image superluigi · Aug 20, 2014 at 08:19 PM 0
Share

It shouldn't be. I think you're complicating things. Either I don't understand what exactly it is you're trying to do, or this is an extremely easy fix. Literally like a 1 $$anonymous$$ute fix. Let me know exactly what it is you're trying to do.

Show more comments
avatar image
0

Answer by narilearsi · Apr 09, 2018 at 09:30 PM

try fiddling with Min Penetration For Penalty value found in Edit->Project Settings->Physics 2D. A lower value of 0.001 rather than 0.01 fixed the problem 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

26 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

Related Questions

Stack of RigidBody2D, Freeze X and Z, Odd Behavior 1 Answer

Is it possible to disable collisions for separate physics scene? 0 Answers

Unity Physics Collision Execution Order Error? 1 Answer

Platformer2D Player sticks to platform corners 0 Answers

increasing knockback of a rigidbody as received damage increases (like super smash) 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