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(_groundShapeContainermesh0);
   
body.position = new Vector3D(0,0,0);

   
_physics.addRigidBodyWithGroup(body11);
   
   
body.position = new Vector3D( -40000);
   
mesh.position = new Vector3D( -40000);
   
   
trace("LISTA: "_groundShapeContainer.children);
  
}

  
private function createGroundShape():AWPCompoundShape 
  {
   
var outsideContainer:AWPBoxShape = new AWPBoxShape(800300800);
   var 
insideContainer :AWPBoxShape = new AWPBoxShape(40050800);

   var 
mainContainer:AWPCompoundShape = new AWPCompoundShape();
   
mainContainer.addChildShape(outsideContainer, new Vector3D(000), new Vector3D(000));
   
mainContainer.addChildShape(insideContainer, new Vector3D(300, -5000), new Vector3D(000));
   
   return 
mainContainer;
  
}
    
  
private function createMesh():Mesh 
  {
   
var mesh:Mesh = new Mesh();
   var 
outsideContainer:WireframeCube = new WireframeCube(8003008000xFFFFFF2);
   var 
insideContainer :WireframeCube = new WireframeCube(400508000xFF00001);
   
   
mesh.addChild(outsideContainer);
   
mesh.addChild(insideContainer);
   
   
insideContainer.position = new Vector3D(300, -5000);
   
   return 
mesh;
  
}
  
  
private function createSpheres():void 
  {
   
var _sphereMesh:Mesh;
  
   for (var 
i:int 020i++) 
   

    _sphereMesh 
= new Sphere(_sphereMaterial25);
    
_view.scene.addChild(_sphereMesh);
    
    
_sphereShape = new AWPSphereShape(25);
    
    var 
sphereRigid:AWPRigidBody = new AWPRigidBody(_sphereShape_sphereMesh1);
    
sphereRigid.position = new Vector3D(0400 i0);
    
sphereRigid.restitution 0.1;
    
sphereRigid.linearDamping 0.5;
    
    
//_physics.addRigidBody(sphereRigid);
    
_physics.addRigidBodyWithGroup(sphereRigid11);
    
    
sphereRigid.addEventListener(AWPCollisionEvent.COLLISION_ADDEDcollisionHandlerfalse0true);
   
}
  }
  
  
private function collisionHandler(e:AWPCollisionEvent):void 
  {
   trace
(e.collisionObject);
  

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X