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 SoshJam · Nov 28, 2021 at 06:30 AM · collisionrigidbody2dcollider2d

Rigidbody colliding with every section of floor

I have a floor made of 1m tiles at every square on Unity's grid, each with its own box collider.

I apply horizontal force to my player rigidbody, and it often stops at random floor sections. I believe it is colliding with the microscopic differences in heights of the tiles, even though they are all set to a whole number. Why is this happening?

Edit: Here's PlayerController.cs, seems pretty standard

 private void FixedUpdate() {
     // Move character
     rb.AddForce(new Vector2( horizontalInput * moveAcceleration , 0f ));
     // Clamp maximum velocity
     rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxMoveSpeed);
     // Apply linear drag if input is not active
     rb.drag = Mathf.Abs(horizontalInput) < 0.2f ? linearDrag : 0;
 }
Comment
Add comment · Show 2
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 MilitaryG · Nov 28, 2021 at 06:32 AM 0
Share

Can you show us some code?

avatar image SoshJam MilitaryG · Nov 28, 2021 at 06:37 AM 0
Share

Updated the post

2 Replies

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

Answer by SoshJam · Nov 29, 2021 at 03:24 AM

I created a script to normalize player position:

 public class RemovePlayerBumpiness : MonoBehaviour
 {
     // Stop the bumpiness that comes from moving along the ground
     private Rigidbody2D rb;

     private void Start() {
         rb = GetComponent<Rigidbody2D>();
     }

     private void FixedUpdate() {
         // If player isn't moving up or down, keep y position constant.
         if (Mathf.Abs(rb.velocity.y) < 0.05f) {
             transform.position = new Vector2(transform.position.x, Mathf.RoundToInt(transform.position.y));
         }
     }
 }

It's not a perfect solution but it seems to be working just fine so I'll roll with it for now. I also changed Default Contact Offset to 0.0001 as suggested by @AaronBacon .

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 AaronBacon · Nov 28, 2021 at 11:38 AM

I'm assuming the Player RigidBody in question uses a Box Collider, which is why the corners get stuck. I'm also sure there is probably some solution in the Project Settings under Physics that maybe helps dampen this issue a little, but the generally accepted solution for a player is to use a Capsule Collider:

⠀

Capsule Collider Image ⠀

The reason these are used is that they have no sharp corners, meaning they can go up steps and slopes with no issues, as well as avoiding the issue you're having, since there's nothing to get caught on the edges.

⠀

However, that may not always work, like if you have an actual box, a Box collider just makes sense. From researching, it seems there's not really an agreed solution. From this thread, some suggest using a series of rounded colliders on the edges, some suggest having a tile collider merging script, some say have a script on the box that uses Physics.IgnoreCollision etc. so I guess it's just something that computers aren't really good at and causes issues that you need to workaround.

⠀

EDIT: this thread seems to say that changing the Default Contact Offset Under Project Settings > Physics may help https://www.reddit.com/r/Unity3D/comments/8dvo2c/how_do_i_fix_broken_collisions_where_two/

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 SoshJam · Nov 29, 2021 at 03:23 AM 0
Share

Already using a capsule collider, that's why I'm so confused

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

205 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 avatar image 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

Location of RigidBody2D on collision 3 Answers

Object hits another but doesnt bounce off again. 0 Answers

set collision force after isKinematic disabled 0 Answers

I need help with Vectors, Positions, Rigidbody2d and Lerp. Please help me! 0 Answers

BoxCollider2D failling verification when Instantiate (Fixed, Cause: big derp) 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