Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a problem with my current collision implementation.

Currently for player collision, I just use an AABB where I check if another AABB is in the way of the player, as shown in this code. (The code below is a sample of checking for collisions in the Z axis)

for (int z = (int) (this.position.getZ()); z > this.position.getZ() - moveSpeed - boundingBoxDepth; z--)
{
    // The maximum Z you can get.
    int maxZ = (int) (this.position.getZ() - moveSpeed - boundingBoxDepth) + 1;
    AxisAlignedBoundingBox aabb = WarmupWeekend.getInstance().currentLevel.getAxisAlignedBoundingBoxAt(new Vector3f(this.position.getX(), this.position.getY(), z));
    AxisAlignedBoundingBox potentialCameraBB = new AxisAlignedBoundingBox(this, "collider", new Vector3f(this.position.getX(), this.position.getY(), z), boundingBoxWidth, boundingBoxHeight, boundingBoxDepth);
    if (aabb != null)
    {
        if (potentialCameraBB.colliding(aabb) && aabb.COLLIDER_TYPE.equalsIgnoreCase("collider"))
        {
            break;
        }
        else if (!potentialCameraBB.colliding(aabb) && z == maxZ)
        {
            if (this.grounded)
            {
                playFootstep();
            }
            this.position.z -= moveSpeed;
            break;
        }
    }
    else if (z == maxZ)
    {
        if (this.grounded)
        {
            playFootstep();
        }
        this.position.z -= moveSpeed;
        break;
    }
}

Now, when I tried to implement rotation to this method, everything broke. I'm wondering how I could implement rotation to this block (and as all other checks in each axis are the same) and others. Thanks in advance.

share|improve this question
    
I'd use JBullet physics library. jbullet.advel.cz –  Sri Harsha Chilakapati Sep 12 at 15:10

1 Answer 1

AABBs (Axis-Aligned Bounding Boxes) are (as the name suggests) without rotation. What you need are OBBs (Oriented Bounding Boxes), there are many tutorials on the web but collisions in 3D space are always either not good enough ore a pain in the back.

Wikipedia provides a nice set of formulas ;) http://en.wikipedia.org/wiki/Bounding_volume#Basic_intersection_checks

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.