Possible bug? Rigidbody2D passes through StaticBody2d and KinematicBody2d at high speeds.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zyrixian
:warning: Old Version Published before Godot 3 was released.

Hi,

I’m trying to figure out if this is a bug, or if I’m not implementing this the correct way. I’ve seen a few questions about this online, but nothing that seems like a solution.

I’m making a game similar to pong. right now there is 4 walls and 1 paddle, and a ball. While testing gradual speed increase (by using objects .set_linear_velocity) i notice that the ball often passes through the paddle without colliding. This seems to happen ~50% of the time at high speeds (velocity set to about (1000,1200)) after some time of bouncing around, the ball then seem to eventually pass through one of the walls and I have to start the program over again.

I can’t for the life of me figure out what’s going wrong.

What I tried:
decreasing cell_size in project settings
changing thread_model to multi-core
increase paddle collision margin to 0.3 (from 0.1)
disable Continuous Cd
Use Continuous Cd - cast ray & cast shape
increase size of wall’s collision box (did help a little but ball still eventually passes through)
removing all code that modifies velocity and setting velocity y @ 1200 at start

Thanks in advance for the help!

This is a common problem in physics engines, known as “tunnelling”, and mostly happens in discrete collision mode because the distance travelled between two frames is bigger than the size of the objects. Continuous detection mode or a smaller physics time step are supposed to improve it at the cost of performance. You can also try to increase the size of colliders at high speed or use long-range raycasts to predict the impacts, but since you seem to have already tried that I’m out of ideas too :confused:

Zylann | 2016-09-30 10:40

Thanks for the reply. That’s good to know, at least I’m on the right track. Perhaps I’m not implementing it correctly?

The only thing I did was turn it on in the rigid object (the ball), using the inspector tab.

It actually looks like it’s not making a difference at all. Perhaps it’s not working? Or is there something else I have to do?

zyrixian | 2016-09-30 14:32

Last time I had this problem was in Unity and enabling CCD was enough to fix it. If it isn’t, the other options have to be considered. I honestly don’t know what CCD supports in Godot, maybe it doesn’t supports Mobile // Mobile collisions but only Mobile // Static?

Zylann | 2016-09-30 16:18

:bust_in_silhouette: Reply From: rgrcnh

I am figuring out how collide a kinematicbody2d with a staticbody2d.

I set up a simple game with the two objects and their children (sprite and a collsionShape2D using a RectangleShape2D, each). I adjusted the RetangleShape2D inside both CollisonShape2D to circumvent the sprites.

The kinematic is passing over (or under) the staticbody, what I think is a wrong behavior.

I’am using Godot 2.1-stable-x11.64

Someone have a clue about that?

I realized that I can’t use set_pos() and expect to detect collisions. The collision works only with move()

rgrcnh | 2016-09-30 21:58