Class ColliderComponent

java.lang.Object
technology.sola.engine.physics.component.ColliderComponent
All Implemented Interfaces:
technology.sola.ecs.Component

@NullMarked public class ColliderComponent extends Object implements technology.sola.ecs.Component
ColliderComponent is a Component that contains collision data for an Entity. The currently supported ColliderShapes are:
  • Constructor Details

    • ColliderComponent

      public ColliderComponent(ColliderShape<?> colliderShape)
      Creates a ColliderComponent instance with specified ColliderShape.
      Parameters:
      colliderShape - the ColliderShape
    • ColliderComponent

      public ColliderComponent(ColliderShape<?> colliderShape, float offsetX, float offsetY)
      Creates a ColliderComponent instance with specified ColliderShape and collider offset.
      Parameters:
      colliderShape - the ColliderShape
      offsetX - the collider x-axis offset
      offsetY - the collider y-axis offset
  • Method Details

    • getOffsetX

      public float getOffsetX()
      Returns:
      the x offset from the transform
    • getOffsetY

      public float getOffsetY()
      Returns:
      the y offset from the transform
    • getBoundingBox

      public Rectangle getBoundingBox(TransformComponent transformComponent)
      Returns the bounding box for this ColliderComponent.
      Parameters:
      transformComponent - the TransformComponent of the Entity
      Returns:
      the bounding box
    • isSensor

      public boolean isSensor()
      A collider that is a sensor will not respond to collision resolution but will emit collision events if an Entity with a DynamicBodyComponent collides.
      Returns:
      true if this collider is a sensor
    • setSensor

      public ColliderComponent setSensor(boolean isSensor)
      Sets whether this collider is a sensor or not.
      Parameters:
      isSensor - whether this collider is a sensor or not
      Returns:
      this
    • getTags

      public ColliderTag[] getTags()
      Returns:
      the ColliderTags for this Collider
    • setTags

      public ColliderComponent setTags(ColliderTag... tags)
      Sets the ColliderTags for this collider.
      Parameters:
      tags - the new tags
      Returns:
      this
    • hasTag

      public boolean hasTag(ColliderTag colliderTag)
      Checks to see if this collider has a ColliderTag.
      Parameters:
      colliderTag - the tag to check
      Returns:
      true if collider has tag
    • getIgnoreTags

      public ColliderTag[] getIgnoreTags()
      Returns:
      the ColliderTags to ignore for this Collider
    • setIgnoreTags

      public ColliderComponent setIgnoreTags(ColliderTag... ignoreTags)
      Sets the ColliderTags to ignore for this collider.
      Parameters:
      ignoreTags - the new tags to ignore
      Returns:
      this
    • hasIgnoreColliderTag

      public boolean hasIgnoreColliderTag(ColliderTag colliderTag)
      Checks to see if this collider has a ColliderTag that it is ignoring.
      Parameters:
      colliderTag - the tag to check
      Returns:
      true if collider is ignoring tag
    • getShape

      public <T extends Shape> T getShape(TransformComponent transformComponent)
      Gets the geometric Shape representation of the collider for collision calculations.
      Type Parameters:
      T - the type of the Shape
      Parameters:
      transformComponent - the Entity's current TransformComponent
      Returns:
      the Shape of the collider
    • debugRender

      public void debugRender(Renderer renderer, TransformComponent transformComponent)
      Renders a debug overlay over the collider.
      Parameters:
      renderer - the Renderer
      transformComponent - the Entity's TransformComponent
    • getType

      public ColliderType getType()
      Gets the ColliderType of this collider.
      Returns:
      the ColliderType of this collider