rowila's picture
+0

Hi, I think it is a beginner question. What is the best way to detect the contact between two or more objects or layers ? As example: Two dice fall to the ground and collide and jump in different directions depending on the edges as they touch.

Thanks,...

Rolf

Comments

1 Answer

Pianomatic's picture
+2

Here's a composition that demonstrates a rudimentary way of detecting collisions. It doesn't deal with objects bouncing off of one another. That, I leave to you, though I'd wait for the physics simulation nodes if I were you.

The synopsis: Two rectangular layers float about the screen. When when one rectangle's vertex enters the other layer, a collision is "detected" and a collision message is flashed on the screen.

Note: This registers extra collisions in cases where the two layers overlap, but all eight vertices happen to be outside of their opposites' rectangle. Think of two rectangles that overlap to form an X, then one slide off the other. One could improve things by also checking, say, midpoints along the edges, and further by adding more points to check, though there's a point (pun unintended, but I'm not changing it) at which performance will suffer.