Problem with collision detection - $50 for the fix!

Hey all,

I could use a really quick fix for this one - I am creating a top down racing game (how original!) for a client and to create bends in the road, I have a whole bunch of boxes and I'm modifying their top 2 vertices to make a 'curve out of straight lines' sort of effect. The boxes are then stacked beside eachother.

Problem is, once I create it, only about 4 of the 12 or so boxes work with the collision detection - a group of them in the middle. None of the shapes are concave, they're all just modified boxes, and they don't overlap (although I don't think that should make a difference, right?). I'm using the latest Box2D build.

Here is the code that is building the shapes:

Code:
         // bottom curve
         var shapesArray:Array = new Array();
         
         var curveBody : b2BodyDef = new b2BodyDef();
         var newY:Number;
         
         // make each box
         for(var i:int = 0; i<_curveResolution; i++) {
            var curveBox:b2PolygonDef = new b2PolygonDef();
            var x:Number = i - (_curveResolution/2);
            curveBox.SetAsOrientedBox(0.95, 0.95, new b2Vec2(i*2,ENTRY_POINT_Y_BOTTOM));
            
            if(i>0){
               // top left vertex is the same as the previous top right vertex
               curveBox.vertices[0].y = newY;
            }else{
               // first vertex
               curveBox.vertices[0].y = -(_curveResolution/2)/(1 + Math.exp(-x)) + _curveOffsetY;
            }

            // use a sigmoid curve to place the top right vertex
            newY = -(_curveResolution/2)/(1 + Math.exp(-x)) + _curveOffsetY;
            
            curveBox.vertices[1].y = newY;
            shapesArray.push(curveBox);
         }
         // this adds the body and shapes to the world. They appear successfully in the debugger, but some don't collide with the car.
         shapes.push(new TrackSegmentPieceDefinition(curveBody, shapesArray));


Any help would be really appreciated!!! Anyone know how to get all the boxes working?


Rich.
What values have you given ENTRY_POINT_Y_BOTTOM and _curveOffsetY?
Try using debugDraw to double check they are being created in the right place.

Or consider transitioning to shaktools new edge shapes, which allow segmented curves with less hassle.
Hey all,

OK, so I gather this isn't a common problem? I'm using debugdraw and everything is in the correct place, that code creates a row of 12 or so boxes beside eachother, I've attached an image that shows it. You can also see the swf at http://www.richlowenberg.com/clients/car.swf. I'm reluctant to post the full code because I've signed an NDA and I'm not sure it would be allowed.

entry point y bottom and _curveOffsetY are arbitrary values, they just let me place the pieces in the right place.

Thanks for the help guys!


Rich.

Attachment:
car.png
Another clue - when I move the boxes left or right, the working boxes change - they always seem to be in the same area. My world bounds are pretty large though. Any ideas?
SOLVED - My problem was that I was adjusting the world bounds on the fly according to where the car moved, and that was switching off any boxes outside a certain area. Thanks for the help everyone!


Rich.

Original thread: https://box2d.org/forum/viewtopic.php?t=1885