2D Character (circle) "slips" through tiles. Sometimes. Frequently. Video attached.

I have a character which is a ball using a polygon collider 2d (with rigidbody), and my map is made from tiles, using tilemap collider 2d and composite collider 2d.

In order to move my ball, I’m setting the rigidbody velocity directly.
e.g.

Rigidbody2D.velocity = new Vector2(inputX * Speed * Time.fixedDeltaTime, Rigidbody2D.velocity.y);

I also tried using AddForce(), but it doesn’t solve the problem.

Sometimes everything is fine, but sometimes the character just falls through the tiles.

What am I missing?

Attached video showing an example of slipping through:

6fny0

How are you making the ball move? Rb.MovePosition? Forces? Transform.Translate/position?

ha I should of wrote that, my bad.

I’m setting the rigidbody velocity directly.
e.g.

Rigidbody2D.velocity = new Vector2(inputX * Speed * Time.fixedDeltaTime, Rigidbody2D.velocity.y);

I’ll also edit the original pot to add it; it should of been there in the first place.

p.s.
I tried to use AddForce() instead. However, the issue still happens in that case as well

No worries :slight_smile:

So my first though was that perhaps you may have been setting the position directly (Rigidbody.MovePosition or Transform.Position). With a delta large enough, you could accidentally place your object within (or even past) a collider.

This is clearly not the case as you’re setting the velocity / adding forces.

My next suggestion would be to try to set your collision detection (on the Rigidbody of your sphere) to continuous instead of Discrete (default). Basically continuous looks at the first contact point of a collision and tries to correct moving objects from accidentally passing through other colliders by moving them back to that first contact point… This often happens when objects are moving really fast or if you’re dealing with thin colliders. You can read more about it here:
Unity - Manual: Continuous collision detection (CCD) (3D)
Unity - Manual: Introduction to Rigidbody 2D (2D)

Give that a shot and see if it works

1 Like

I didn’t say that either, but it’s already at continuous - the problem still happens.
I’m not sure what info needed, so sorry for not specifying ahead.

Also note someone at the Discord channel gave me a solution, sort of:
The Tilemap Collider 2d has a geometry type, which is by default set to outline.
I set it to polygon - and now the character doesn’t fall through.

I still feel like there’s something going on here, not to mention it’s definitely a hit in performance, so if anyone knows about a better solution I would love to know. But for now anyway, it works.

Similar problem here, use geometry type, which is set to outline, cause rigidbody2d.velocity equals to (-5.02269e-07, 0) when rgbd2d is not moving. Set to polygon, problem solved.

Really want ot know why.
Here is my question link: https://forum.unity.com/threads/my-project-prints-rigidbody2d-velocity-y-3-814697e-06-but-other-project-prints-0.1336931/#post-8445725

Please don’t necro threads. Your question isn’t related to this thread.