godot icon indicating copy to clipboard operation
godot copied to clipboard

RigidBody2D inconsistent bounces near the junction between two squared tiles

Open Yann-Situ opened this issue 2 years ago • 5 comments

Godot version

4.0-stable

System information

Ubuntu 20.04.6

Issue description

A round RigidBody2D colliding near the junction of two squared tiles can result in wrong and inconsistent bounces. Typically, a RigidBody2D going strictly vertical can result in a bounce with some horizontal velocity.

Possible Related issues:

  • The issue appear with the different possible continuous_cd values, but setting it to cast_ray also induces a weird damping behavior (see also #76621).
  • The same configuration often induces tunneling.
  • RigidBody2D continuous collision detection non-functional under Cast Shape setting: #72674.
  • RigidBody2D gets stuck while moving parallel in contact with multiple floors/walls: #47148

Workaround ideas

https://user-images.githubusercontent.com/51318484/235353411-87f2a443-1dcc-40c4-b582-f6c0f87a984a.mp4

Steps to reproduce

Create a Tilemap with squared tiles whose collision shapes are full squares. Create balls (RigidBody2D with round collision shape and a high enough bounce value) and place them above a tile junction, with a small horizontal offset. Run and watch the balls bouncing. The issue itself is inconsistent: it happens with specific physics parameters at specific positions. To reproduce it correctly, one has to play with those parameters.

Minimal reproduction project

ball-weird-bounce.zip

Yann-Situ avatar Apr 30 '23 12:04 Yann-Situ

Still relevant in 4.1. It also makes a simple rolling ball bouncing for no reason on flat ground. If it can't be fixed without baking I think this option deserve to be included in the Tilemap tool

yanourt avatar Sep 18 '23 12:09 yanourt

Can confirm this issue on v4.1.1.stable.official (ignore gravity changes, these are triggered by keyboard) As you can see collisions seems to work weird in between tiles. (bounce is disabled on this clip, yet the ball "skips" sometimes, like it has hit something.)

https://github.com/godotengine/godot/assets/109681545/8426140a-9e10-41a9-b7ff-8ba899711e4f

DevChimera avatar Oct 01 '23 23:10 DevChimera

Encountered this problem while developing my current game, where I kick a ball creature around to finish a level. The ball is implemented using RigidBody2D to make it's behavior realistic. I avoid most of the problems by prebaking the collision shapes into the tilemap but it doesn't work with slopes, which I still have configure manually in a tileset. The bug discussed here produces several problematic scenarios, all happening because the ball hits the edge between tile and slope collision shapes.

  1. Ball gets stuck under the collision shapes.

https://github.com/godotengine/godot/assets/34010694/a2adbb06-98db-40c1-a179-c0593f073651

  1. When I call the ball to my position, it can get blocked and cannot move, as it is held by something.

https://github.com/godotengine/godot/assets/34010694/a0b9aacc-9908-4595-b53d-7463675a9405

  1. Sometimes the ball gets crazy and teleports.

https://github.com/godotengine/godot/assets/34010694/1d8a29a7-4dbf-4fb3-9098-b52ea98c71a7

  1. The ball bounces back when thrown as if it hits a wall.

https://github.com/godotengine/godot/assets/34010694/a9e71c25-96c8-4207-8750-46a683345ddf

As you can see, this is rather nasty bug and I would dare to say that it should take a high priority as it can deter some Godot users from using the engine. It's not easy to create workarounds. I think I presented interesting real world situations which hopefully motivate someone to investigate and fix the problem. Right now I cannot imagine making a game with the use of a tilemap and RigidBody2D objects, especially when using slopes. Grenades bounce back at player, movable objects get stuck on the floor... There are many situations where the bug can completely spoil the experience.

Paar86 avatar Jan 13 '24 15:01 Paar86

I am interested in this issue has there been any updates or possible leads?

SommAid avatar Apr 15 '24 23:04 SommAid

still an issue in 4.2.2 would really love any sort of fix

Terratype avatar Jun 29 '24 02:06 Terratype

If your level geometry is static, you probably want to pre-bake collisions to avoid this for now: https://github.com/godotengine/godot/issues/47148#issuecomment-1412983426

Calinou avatar Jun 29 '24 23:06 Calinou

Should mention that the Rapier2D plugin doesn't have this issue, and seems to be on its way to become the overall better choice for 2D physics, like Jolt has become for 3D.

Rapier2D plugin

Griiimon avatar Aug 08 '24 09:08 Griiimon

this is likely fixed with #102662, should be in 4.5 release

anthony-barricelli avatar May 18 '25 07:05 anthony-barricelli