How could I implement 3D player collision with rotation in LWJGL?
Posted
by
Tinfoilboy
on Game Development
See other posts from Game Development
or by Tinfoilboy
Published on 2014-08-18T23:03:11Z
Indexed on
2014/08/19
4:33 UTC
Read the original article
Hit count: 253
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.
© Game Development or respective owner