[Technical] How does Construct 2 manage collision?

Discussion and feedback on Construct 2

Post » Tue May 22, 2012 3:37 pm

I used to write my own C++ game from scratch, and I used some data structure such as Quadtree, when there are many objects to speed collision checking up.

So I am wondering, how does Construct 2 manage collision technically?
B
2
G
1
Posts: 38
Reputation: 526

Post » Tue May 22, 2012 5:17 pm

C2 SDK sounds like the place to check for the codes insight, in peculiar th cr functions rect, quad and their "intersects" methods.Kyatric2012-05-22 17:18:05
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Tue May 22, 2012 6:22 pm

Looking at the code it just checks every pair of objects for a collision. It compares bbox first, then rotated box, and poly collisions last. When using behaviors such as 8-direction, the object is compared with every soild object. When using the "is overlapping" condition of sprites only the picked objects are used in the comparison, so you could do some sort of quadtree or spacial hash in events before using "is overlapping".
B
79
S
24
G
53
Posts: 4,735
Reputation: 40,233

Post » Tue May 22, 2012 10:24 pm

Both Constructs have always just used an axis-aligned bounding box test to test very quickly if there's no collision (4 number comparisons), then a bounding quad intersection (2 quad intersection), then the full collision poly intersection check. I've been meaning to add some kind of system to reduce the number of comparisons that need to be made, but to be honest, for 2D games the axis-aligned box test is so fast and discards almost all candidates so quickly that I've not felt there's a pressing need for it. You really need thousands of objects before it slows down as it is, and if you use tiled backgrounds properly, you're unlikely to reach that object count.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk, newt and 10 guests