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:
Any help would be really appreciated!!! Anyone know how to get all the boxes working?
Rich.
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));
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.