Wednesday, June 30, 2010

Away3D Tutorial: Accessing Object Group Index from Bounding Box Collision Detection

Accessing Object Group Index from Bounding Box (Feb 24th 2010)

When the collision of a bounding box occurs in my 3D game I wanted to know which character the bounding box belongs too. The "character" is really an obectContainer in an array of objectContainers. Each element in the array represents one character and each element is an obectContainer containing the character model, bounding box and any accessories so they all travel together. The bounding box collision is therefore representative of it's parent's obectContainer collision "with another obectContainer" (which also has a bounding box).

So, I supposed the simplest way to do this would be to edit the Cube primitive class to contain an integer index to use to access other objects in the same group via their respective arrays.

I put the following into the Cube6.as Cube class file:

...
/**
* Creates a 3d Cube primitive.
*/
public class Cube6 extends AbstractPrimitive
{
private var _width:Number = 100;
private var _height:Number = 100;
private var _depth:Number = 100;
private var _segmentsW:int = 1;
private var _segmentsH:int = 1;
private var _segmentsD:int = 1;
private var _pixelBorder:int = 1;

//CGG Added
//Accessing Object Group Index from Bounding Box (Feb 24th 2010)
//Edit the Cube primitive class to contain an integer index to use to access other objects in the same
//group via their respective arrays including obectContainer and mesh(es).
public var groupIndex:int;

...


The var groupIndex:int; is public so we can set and get ourselves. Not ideal but it works.

1 comment:

  1. Any chance we could get a tutorial or something about Bounding Box collisions? I'd like to know when 2 of my models are touching!

    ReplyDelete

Give me your best comment. *_*