Class BoxCollider


public class BoxCollider extends Collider
A rectangular collider used for detecting collisions between box-shaped GameObject instances. This collider uses axis-aligned bounding box (AABB) intersection logic to determine overlaps with other BoxCollider instances.

Usage:

     MyGameObject gameObj = new MyGameObject();
     gameObj.addPhysicsComponent(new BoxCollider(gameObj, 1, 1));
 

You can also use GameManager to register and move Entity's:

     MyEntity entity = new MyEntity();
     entity.addPhysicsComponent(new BoxCollider(entity, 1, 1));
     gameManager.getGameRegister().registerEntity(entity);

     // update to new location.
     gameManager.getGameRegister().getPhysicsManager().tryMove(entity, newLoc);
 
Since:
1.0-dev
Author:
ColleBol - contact@collebol.org
  • Constructor Details

    • BoxCollider

      public BoxCollider(GameObject owner, GameLocation originLocation, double width, double height)
      Constructs a new BoxCollider for the given game object with the specified width and height.
      Parameters:
      owner - the GameObject that owns this collider
      originLocation - the center point of the collider. (0.5 is half)
      width - the width of the collider in world units (tileSize, so 1 is one tile)
      height - the height of the collider in world units (tileSize, so 1 is one tile)
  • Method Details

    • intersects

      public boolean intersects(Collider other)
      Checks whether this collider intersects with another collider.

      If the other collider is also a BoxCollider, an axis-aligned bounding box (AABB) intersection test is performed. If the other collider type is unsupported, this method returns false.

      Specified by:
      intersects in class Collider
      Parameters:
      other - the other collider to check intersection with
      Returns:
      true if the colliders intersect, false otherwise
    • getWidth

      public double getWidth()
    • setWidth

      public void setWidth(double width)
    • getHeight

      public double getHeight()
    • setHeight

      public void setHeight(double height)