Continuous Collision Detection (DEF-3115)

I want to be able to enable Continuous Collision Detection on physics objects! It should be a checkbox in the collision object properties in the editor.

I know it’s possible to hack something like CCD together with raycasts, but it’s kind of a pain in the butt, it’s not as good, and it’s way more work than a simple checkbox in the editor. I’ve spent the last several hours trying to stop my platformer character from tunneling through platforms, and haven’t found a satisfactory solution yet.

Some issues that would be solved by this checkbox:

Anyone making Pong, Breakout, or any game requiring precise bouncing (even with kinematic objects)
Example: High velocity move and collision

Anyone who wants relatively fast bullets.
Example: Collision detection with many bullets

4 Likes

Hmm, what’s causing the tunneling? Does it happen under special circumstances. Generally speaking it should work fine to resolve collisions based on contact_point_response messages, shouldn’t it?

2 Likes

It’s just a matter of velocity and size. Anything that can move further than its size in one frame is at risk of passing through objects. And that’s really not very fast. Especially if you figure that the frame rate might drop down as low as 30, for whatever reason.


(Side note: I am using this recording feature all the time since it was fixed in 1.2.119!)

I think I may have found an acceptable workaround for my case. It’s mostly a matter of knowing what order things happen in. It’s script update > contact_point_response > ray_cast_response (for rays cast in update) > render update. So if you have a workaround CCD check with ray casts, you have to know and account for any changes made by your contact_point_response between calling and receiving the raycast . . .

But all this should be unnecessary, (and it’s presumably much slower than if the physics engine handled it.) Both Box2D and Bullet have CCD. The Stencyl engine (using Box2D) even has it enabled on all objects by default.

6 Likes

vote up for the feature request: “improvement physics in Defold” to add more features from box2d

  • CCD
  • velocity property for dynamic objects
  • allowing to set up the collision object physics properties in runtime: mass, mask, group

that will allow to make more flexible and complex physics games in Defold.

6 Likes

+1

2 Likes

CCD is good on it’s own, but it will not help you make robust & predictable platformer mechanics. Ray casting is the ONLY option here. You will realize this as soon as you start making self-moving platforms, movable objects (and mix of that), instead of only static geometry.

2 Likes

Yes, this issue is quite unfortunate.
The CCD already is enabled in Box2D (it’s on by default). EDIT: I since found that the flag “isBullet” currently defaults to false. (Added DEF-3118 for this)
Unfortunately, our tile grid shape has some flaws that makes it not work correctly with CCD. We are looking into ways of improving our implementation.

Note, however, that CCD doesn’t affect kinematic objects (which I presume your character is?). This is because you can at anytime teleport the object to be completely inside another object.

Here, again, it’s our tile grid collision shape that needs better contact/normal reporting in order for the resolve step to work correctly. I’ve created DEF-3115 for this.

One step towards better collision for dynamic objects vs tile grids, is coming in DEF-2956 (next sprint). But alas, it won’t solve the general case for kinematic objects.

8 Likes

Ah! Well that’s interesting! I guess I put my foot in my mouth (again).

Yes, I am using a kinematic object. Hmm . . . I did try using a dynamic body for a platformer before, but of course they’re a bit harder to control. Maybe I will look into it again to see if it would cause more trouble than it would solve. Good to know about the tile collisions, I look forward to those fixes!

@dmitriy - You are right, my current use-case is very simple. If you care to elaborate or share code, I would be grateful to know about the pitfalls before I run into them myself.

1 Like

Hey Ross,

I’m running into something like this as well, with kinematic-type player and enemy objects colliding primarily with tile maps.

In a previous incarnation I was using an actual collision object on the player, set to Kinematic, and using contact_point_response in an expanded implementation of the basic platformer tutorial. I had about 90% of everything working perfectly within a couple of days, being completely new to programming, which I was pretty proud of.

Then I spent about 2.5 weeks struggling to get sloped (just 45 degrees) platforms working, and never was able to manage it consistently. Frustrated, I dumped the whole project and started from scratch.

Now, my player character does not have any collision object attached at all (well, he does, but it’s for enemy interactions, damage and such). He is colliding with the tilemap strictly through code. What I’m doing is probably highly inefficient, unfortunately I don’t know enough about what I’m doing to know…but it has solved ALL of my collision issues, including the “bullet through paper” problem you’re having, as well as allowed me to easily implement specific sloped terrain (we’re only using 45s. Other angles would present more of a challenge…)

It’s basically this:

Each tile in the tilesource is stored in a descriptive table. The tables look kind of like:
solid = 1, 3, 4, 10, 11, etc
left_slope = 2, 5, 6, etc
right_slope = 7, 8, 9, etc
(a more thought out tile sheet would make this a little easier, but whatever :slight_smile: )

I have a module with conditions set out for what to do in the scenario of each type of tile, divided up into separate x and y movement (basically calling a “move x” function and then a “move y” function).

The player character itself can be given a move instruction, say “move 10 pixels to the right, and 8 pixels down.” These are passed into the appropriate x or y movement module functions as x = 10, y = -8

These functions run a loop for the absolute value of the number passed to them (so, 10 loops for x, and 8 loops for y), and convert the sign to a direction (+1 or -1) internally in the loop.

For each pixel of requested movement (so, each loop) the appropriate checks against the tiles are made, and if movement is not possible, the loop kicks out and returns the total amount of movement possible before collision. These x and y values are returned back to the player script as the final destination for the next frame, so collisions are actually prevented before they happen.

I’m fairly certain this is re-inventing the wheel in a lot of ways, but the bottom line is 3 weeks of fighting against built-in kinematic collision got me nowhere (almost certainly my fault due to lack of experience), and 4 days of building this way got me exactly what I wanted. I’ve dropped 75+ “player” characters into a single screen all moving based on this module, and there has been no measurable slowdown at all. In actual gameplay, there will be at most 15-20 entities existing at one time on screen (the rest spawning and deleting as they move on/off screen) so I don’t really foresee any performance issues here, but who knows.

Anyway, not sure if this type of method would help you, just something I dreamed up one evening at my local and I’m happy so far with how it’s working for my particular project.

-RSL

4 Likes

Since my last reply I found that the “IsBullet” in Box2D flag actually defaults to false. I’ve added ticket DEF-3118 for being able to control this flag.

6 Likes

This was released in Defold 1.2.121

2 Likes