Strange collision problem :(

Software: Away3D 4.x

Maniek, Newbie
Posted: 19 October 2011 03:54 PM   Total Posts: 4

I have a question: when i add rigidbody(ball) to _view.scene directly, collisions work, everything is ok. But when i add rigidbody to ObjectContainer3D(car) (because i need local coordinates of ball), physics cannot detect collisions. My rigidbody has always the same position, even if i move ObjectContainer!

To picture the problem:

I’m driving a car in various directions (x axis, z axis) and I want a ball that’s moving 25 pixels to the right of the car to collide (the ball collides but the car doesn’t)

Question: I need local coordinates and collisions of my rigidbody. How can i add this rigidbody to other container (or other rigidbody?!)

Sorry for shitty english smile

   

Yang Li, Administrator
Posted: 20 October 2011 01:07 AM   Total Posts: 80   [ # 1 ]

you can use AWPCompoundShape, look CompoundShapeTest in examples

 

   

Maniek, Newbie
Posted: 20 October 2011 12:40 PM   Total Posts: 4   [ # 2 ]

ok, thanks! AWPCompundShape can contain more shapes now, but how can i make parent container invisible for collisions? Look at attachment.

 

fragment of code:

private function initObjects():void 
  {
   createGround
();
   
createSpheres();
  
}
  
  
private function createGround():void 
  {
   
var _groundShapeContainer:AWPCompoundShape = createGroundShape();
   
   var 
mesh : Mesh;
   var 
body : AWPRigidBody;
   
   
mesh = createMesh();
   
_view.scene.addChild(mesh);
   
   
body = new AWPRigidBody(_groundShapeContainer, mesh, 0);
   
body.position = new Vector3D(0,0,0);

   
_physics.addRigidBodyWithGroup(body, 1, 1);
   
   
body.position = new Vector3D( -400, 0, 0);
   
mesh.position = new Vector3D( -400, 0, 0);
   
   
trace("LISTA: ", _groundShapeContainer.children);
  
}

  
private function createGroundShape():AWPCompoundShape 
  {
   
var outsideContainer:AWPBoxShape = new AWPBoxShape(800, 300, 800);
   var 
insideContainer :AWPBoxShape = new AWPBoxShape(400, 50, 800);

   var 
mainContainer:AWPCompoundShape = new AWPCompoundShape();
   
mainContainer.addChildShape(outsideContainer, new Vector3D(0, 0, 0), new Vector3D(0, 0, 0));
   
mainContainer.addChildShape(insideContainer, new Vector3D(300, -500, 0), new Vector3D(0, 0, 0));
   
   return 
mainContainer;
  
}
    
  
private function createMesh():Mesh 
  {
   
var mesh:Mesh = new Mesh();
   var 
outsideContainer:WireframeCube = new WireframeCube(800, 300, 800, 0xFFFFFF, 2);
   var 
insideContainer :WireframeCube = new WireframeCube(400, 50, 800, 0xFF0000, 1);
   
   
mesh.addChild(outsideContainer);
   
mesh.addChild(insideContainer);
   
   
insideContainer.position = new Vector3D(300, -500, 0);
   
   return 
mesh;
  
}
  
  
private function createSpheres():void 
  {
   
var _sphereMesh:Mesh;
  
   for (var 
i:int = 0; i < 20; i++) 
   
{ 
    _sphereMesh 
= new Sphere(_sphereMaterial, 25);
    
_view.scene.addChild(_sphereMesh);
    
    
_sphereShape = new AWPSphereShape(25);
    
    var 
sphereRigid:AWPRigidBody = new AWPRigidBody(_sphereShape, _sphereMesh, 1);
    
sphereRigid.position = new Vector3D(0, 400 * i, 0);
    
sphereRigid.restitution = 0.1;
    
sphereRigid.linearDamping = 0.5;
    
    
//_physics.addRigidBody(sphereRigid);
    
_physics.addRigidBodyWithGroup(sphereRigid, 1, 1);
    
    
sphereRigid.addEventListener(AWPCollisionEvent.COLLISION_ADDED, collisionHandler, false, 0, true);
   
}
  }
  
  
private function collisionHandler(e:AWPCollisionEvent):void 
  {
   trace
(e.collisionObject);
  
} 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X