does c2 test for collisions twice when using physics?

Discussion and feedback on Construct 2

Post » Mon Jan 19, 2015 10:52 pm

-Answer-

Construct does do this but only in specific cases.

"...(disabling c2 collisions) will have no effect (on performance) if you don't test for collisions in events. If you make no collision tests yourself, then the C2 engine doesn't make any collision tests either, so it's irrelevant whether the object has collisions enabled or disabled.

I don't think there's any way around having the two collision tests - not all games use a Physics engine, so C2 needs its own engine. But as I say if you don't use collision events on an object then it will only use the Box2D collision engine." -Ashley

*** ORIGINAL POST ***

Hey everybody,

Does anyone know if construct 2 is using box2d internally for collision detection? Or is it using a custom system to test overlap.

It seems efficient either way, but I wondered if it did implement its own algorithms, wouldn't it basically be doing double time when you are running physics on an object as well? Because you don't ask physics if something has collided... you have to ask construct 2 if something is overlapping...

Just doing some exploring...

***END ORIGINAL POST***
Last edited by ruskul on Wed Jan 21, 2015 2:14 am, edited 2 times in total.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Mon Jan 19, 2015 11:44 pm

I don't know how it works when you are using physics, but C2 definitely has it's own internal collision system that has nothing to do with Box2D.

Basically, the way I understand it, the collision system takes the following 'top down' approach:

1. Only compare an object against other objects in it's current collision cell(s).

2. Start by doing a cheap boundary box test to see if the BB of ObjA is intersecting the BB of ObjB.

3. If so, do a more expensive polygonal collision test, where the engine checks if the polygons of the two objects intersect anywhere.

4. If physics are involved, I'm guessing that the poly test is handed off to the Box2D behavior, which tests for collisions using it's own internal algorithms. But...I could be wrong about that.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Tue Jan 20, 2015 1:31 am

@TiAm
I just came up with a way to test. I created a bouncing ball project and disabled construct 2 collisions. Physics ran without a hitch. This means any object with physics is having multiple collision algorithms run on it...

I need to set up some tests... I am curious what this collision testing overhead is.

steps 1 and 2 are fast so I am sure it is nominal... but it may add for some interesting optimizations that could occur in a project. Box2d supplies collision information, but it is not exposed to c2. If you want to know if an object is hitting another you have to use c2 algorithm.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Tue Jan 20, 2015 2:02 pm

ruskul wrote:You can disable c2 collisions for a performance boost

This will have no effect if you don't test for collisions in events. If you make no collision tests yourself, then the C2 engine doesn't make any collision tests either, so it's irrelevant whether the object has collisions enabled or disabled.

I don't think there's any way around having the two collision tests - not all games use a Physics engine, so C2 needs its own engine. But as I say if you don't use collision events on an object then it will only use the Box2D collision engine.
Scirra Founder
B
400
S
236
G
89
Posts: 24,549
Reputation: 195,475

Post » Wed Jan 21, 2015 2:07 am

@Ashley - that's cool, real cool. So there really is no reason to go through a project and disable collisions on objects you don't need to collisions...? Nice... in that case... *editing OP*
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests