Hiya all! I’m goofing around with away physics just to get the hang of it, and I’m having some problems with tiling AWPRigidBody. I’ve been modifying the vehicle terrain demo and the reason why I’m tiling is that I want to be able to drive forever without falling off the terrain, hence the wrapping.
But It doesn’t wrap in a correct manner. I’ve created a cloud filtered image in Photoshop, and as you all probably know, it’s tiling perfectly when you make the size power of 2. So I made the heightmap image 256x256. I’m using 4 tiles that I move around depending on where the car is on the current tile.
Here I create the AWPTerrain instance:
var terrain : AWPTerrain = new AWPTerrain(bmaterial, terrainBMD.bitmapData.clone(), 20000, 3100, 20000, 200, 200, 3000, 0, false);
and here in the render method I move around the tiles:
var ind2:int = 0;
for each(var tBod2:AWPRigidBody in _terrainBodies) {
var tBodPos:Vector3D = _terrainBodies[ind2].position as Vector3D;
if(carPosition.x <= tBodPos.x + (TILE_WIDTH / 2) &&
carPosition.x >= tBodPos.x - (TILE_WIDTH / 2) &&
carPosition.z <= tBodPos.z + (TILE_WIDTH / 2) &&
carPosition.z >= tBodPos.z - (TILE_WIDTH / 2)) {
_currentTile = ind2;
break;
}
ind2++;
}
var terrainBody:AWPRigidBody = _terrainBodies[_currentTile] as AWPRigidBody;
var terrainBodyPos:Vector3D = terrainBody.position;
var oldCurrentZone:int = _currentZone;
if(carPosition.x <= terrainBodyPos.x &&
carPosition.z >= terrainBodyPos.z) {
_currentZone = ZONE_NW;
}
else if(carPosition.x >= terrainBodyPos.x &&
carPosition.z >= terrainBodyPos.z) {
_currentZone = ZONE_NE;
}
else if(carPosition.x <= terrainBodyPos.x &&
carPosition.z <= terrainBodyPos.z) { _currentZ
}
else if(carPosition.x >= terrainBodyPos.x &&
carPosition.z <= terrainBodyPos.z) { _currentZ
}
if(_currentZ oldCurrentZone) {
return;
}
var ind:int = -1;
var tmpArr:Array = [];
for each(var tBod:AWPRigidBody in _terrainBodies) {
ind++;
if(ind == _currentTile) {
continue;
}
tmpArr.push(tBod);
}
switch(_currentZone) {
case ZONE_NW:
tmpArr[0].x = terrainBodyPos.x - (TILE_WIDTH);
tmpArr[0].z = terrainBodyPos.z;
tmpArr[1].x = terrainBodyPos.x - (TILE_WIDTH);
tmpArr[1].z = terrainBodyPos.z + (TILE_DEPTH);
tmpArr[2].x = terrainBodyPos.x;
tmpArr[2].z = terrainBodyPos.z + (TILE_DEPTH);
break;
case ZONE_NE:
tmpArr[0].x = terrainBodyPos.x + (TILE_WIDTH);
tmpArr[0].z = terrainBodyPos.z;
tmpArr[1].x = terrainBodyPos.x + (TILE_WIDTH);
tmpArr[1].z = terrainBodyPos.z + (TILE_DEPTH);
tmpArr[2].x = terrainBodyPos.x;
tmpArr[2].z = terrainBodyPos.z + (TILE_DEPTH);
break;
case ZONE_SW:
tmpArr[0].x = terrainBodyPos.x - (TILE_WIDTH);
tmpArr[0].z = terrainBodyPos.z;
tmpArr[1].x = terrainBodyPos.x - (TILE_WIDTH);
tmpArr[1].z = terrainBodyPos.z - (TILE_DEPTH);
tmpArr[2].x = terrainBodyPos.x;
tmpArr[2].z = terrainBodyPos.z - (TILE_DEPTH);
break;
case ZONE_SE:
tmpArr[0].x = terrainBodyPos.x + (TILE_WIDTH);
tmpArr[0].z = terrainBodyPos.z;
tmpArr[1].x = terrainBodyPos.x + (TILE_WIDTH);
tmpArr[1].z = terrainBodyPos.z - (TILE_DEPTH);
tmpArr[2].x = terrainBodyPos.x;
tmpArr[2].z = terrainBodyPos.z - (TILE_DEPTH);
break;
}
And finally here is a screenshot of the mistiling: