I am having a hard time solving a problem, I hope someone could point me to the right direction. My goal is to enable physics in my scene and have a box shape collide with loaded road mesh.
- I have created a road mesh in 3DMax and loaded it using away3dx4 with no problem.
- I created a spaceship mesh in 3DMax, imported and wrapped it with AWPBoxShape with the dimensions of the ship.
Now, how do I get the ship box shape to collide with the loaded road? I read all posts related in this forum, I checked all relevant examples and still I have no answer.
The collision worked fine with 2 box shapes when I tested it.
This is my code now:
//load assets
_loader = new Loader3D();
_loader.load(new URLRequest('embeds/Ships/spaceship.3DS'),null, null, new Max3DSParser());
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onSceneResourceComplete);
_loader2 = new Loader3D();
_loader2.load(new URLRequest('embeds/Terrains/lvl1.3DS'),null, null, new Max3DSParser());
_loader2.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onSceneResourceComplete2);
//handle spaceship load
private function onSceneResourceComplete(e:LoaderEvent):void{
chas = ObjectContainer3D(e.target);
view.scene.addChild(chas);
var mesh:Mesh;
mesh = Mesh(chas.getChildAt(0));
mesh.moveTo(0,150,0);
mesh.geometry.scale(2);
mesh.material.lightPicker = lightPicker;
var cubeShape:AWPBoxShape=new AWPBoxShape(mesh.maxX*2,mesh.maxY*2,mesh.maxZ*2);
var cubeRigidBody:AWPRigidBody=new AWPRigidBody(cubeShape,mesh,1);
physicsWorld.addRigidBody(cubeRigidBody);
cubeRigidBody.friction=1;
cubeRigidBody.position=new Vector3D(0,0,0);
}
//handle road load
private function onSceneResourceComplete2(e:LoaderEvent):void{
var container : ObjectContainer3D = ObjectContainer3D(e.target);
view.scene.addChild(container);
var materia : ColorMaterial = new ColorMaterial(0xfa6c16);
materia.lightPicker = lightPicker;
var sceneMesh : Mesh = Mesh(container.getChildAt(0));
sceneMesh.material = materia;
var sceneShape : AWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(sceneMesh.geometry);
var sceneBody : AWPRigidBody = new AWPRigidBody(sceneShape, sceneMesh, 0);
physicsWorld.addRigidBody(sceneBody);
this.addEventListener(Event.ENTER_FRAME, onFrame);
}
//enter frame
private function onFrame(evt:Event):void{
physicsWorld.step(1/30, 1, 1/30);
view.render();
}
The current output of the code is the spaceship falls through the road.
Any help would be greatly appreciated!