Maybe I should keep my Box2D questions to this thread...
I have a strange problem:
1. Multiple Dynamic Bodies, made up of multiple fixtures.
2. A kinematic Body, made from 1 Polygon Edge, set as a sensor - Called the "Scanner"
The Scanner tries to find the highest point on a pile of bodies. It does this by
1. Use b2FindBodyContacts to check for contact with bodies in pile
2. Work through contacts - b2GetContact()
3. If relevant contact found, see if touching - b2GetContactIsTouching()
4. If touching, move the scanner up the pile
5. Repeat until it no longer touches
` *** Scan for height
b2FindBodyContacts gScan.scanner
scanned = 0
scanLevel = 0
while b2GetContact() > 0
if scanLevel < 1 then scanLevel=1
if b2GetContactIsTouching()
scanLevel=2
fixture = b2GetContactFixtureA()
if fixture = gScan.scannerFixture
fixture = b2GetContactFixtureB()
endif
body = b2GetFixtureBody(fixture)
if body <> gGame.currentBody
scanned = 1
scanLevel=3
endif
endif
`text 300, 200, "Fixture: " + str$(fixture)
endwhile
if scanned = 1
dec gScan.line, 1
b2SetBodyTransform gScan.scanner, gScan.left, gScan.line, 0
endif
As you can see from the video, it thinks it's touching when it clearly isn't. This is not always the case, it sometimes works. The connection line you see can appear even when it successfully realises it is no longer touching.
Any help appreciated!