0

I need to do some simple collision detection in Away3D. I found the away3d.bounds.AxisAlignedBoundingBox class, but it seems I can only check collisions between the bounding box and a Vector.

Is there any way to check the collision between two bounding boxes?

CommunistPancake
  • 597
  • 2
  • 10
  • 22
  • Check this article on Detecting Collisions on Away3D, it's about version 3.6 but it might be good info: http://www.packtpub.com/article/away-3d-detecting-collisions – danii Jul 25 '12 at 08:30

1 Answers1

2

if you are using/can upgrade to 4.4.x, look into Mesh.worldBounds, particularly wordBounds.overlap(someOtherWorldBounds).

Example (away3d setup elided):

// setup objects and materials
cubeMaterial:ColorMaterial;
cube:Mesh;

sphereMaterial:ColorMaterial;
sphere:Mesh;

collideMaterial:ColorMaterial;

cubeMaterial = new ColorMaterial(0x3333FF);
cube = new Mesh(new CubeGeometry(), cubeMaterial);
cube.x = -100;
cube.showBounds = true;

sphereMaterial = new ColorMaterial(0xFF3333);
sphere = new Mesh(new SphereGeometry(), sphereMaterial);
sphere.x = 100;
sphere.showBounds = true;

collideMaterial = new ColorMaterial(0x33FF33);

in your enterFrame handler:

// process your object movement here
if (cube.worldBounds.overlaps(sphere.worldBounds) cube.material = collideMaterial;
else cube.material = cubeMaterial;
view.render();
Tarkin
  • 313
  • 2
  • 9