Class DynamicBodyComponent

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

@NullMarked public class DynamicBodyComponent extends Object implements technology.sola.ecs.Component
ColliderComponent is a Component that contains dynamic body physics data for an Entity.
  • Constructor Details

    • DynamicBodyComponent

      public DynamicBodyComponent()
      Creates a DynamicBodyComponent with a Material.UNIT_MASS_MATERIAL Material.
    • DynamicBodyComponent

      public DynamicBodyComponent(Material material)
      Creates a DynamicBodyComponent with desired Material.
      Parameters:
      material - the Material used
    • DynamicBodyComponent

      public DynamicBodyComponent(boolean isKinematic)
      Creates a DynamicBodyComponent instance with a unit mass Material and desired isKinematic value.
      Parameters:
      isKinematic - whether this dynamic body is treated as kinematic or not
    • DynamicBodyComponent

      public DynamicBodyComponent(Material material, boolean isKinematic)
      Creates a DynamicBodyComponent with desired Material and isKinematic value.
      Parameters:
      material - the Material used
      isKinematic - whether this dynamic body is treated as kinematic or not
  • Method Details

    • applyForce

      public void applyForce(float forceX, float forceY)
      Apply a force to the dynamic body.
      Parameters:
      forceX - force in horizontal axis
      forceY - force in vertical axis
    • applyForce

      public void applyForce(Vector2D forceVector)
      Apply a force to the dynamic body.
      Parameters:
      forceVector - force as a vector
    • getForceX

      public float getForceX()
      Gets the force currently applied on the horizontal axis.
      Returns:
      the force on the horizontal axis
    • setForceX

      public void setForceX(float forceX)
      Sets the force on the horizontal axis. This replaces any forces currently applied on the horizontal axis.
      Parameters:
      forceX - the new horizontal axis force
    • getForceY

      public float getForceY()
      Gets the force currently applied on the vertical axis.
      Returns:
      the force on the vertical axis
    • setForceY

      public void setForceY(float forceY)
      Sets the force on the vertical axis. This replaces any forces currently applied on the vertical axis.
      Parameters:
      forceY - the new vertical axis force
    • getVelocity

      public Vector2D getVelocity()
      Returns:
      the velocity of this dynamic body
    • setVelocity

      public void setVelocity(Vector2D velocity)
      Sets the velocity for this dynamic body.
      Parameters:
      velocity - the new velocity
    • isKinematic

      public boolean isKinematic()
      A kinematic dynamic body will not respond to external forces applied to it.
      Returns:
      true if this dynamic body is kinematic
    • setKinematic

      public void setKinematic(boolean kinematic)
      Updates the kinematic property for this dynamic body. If true it will not respond to external forces applied to it.
      Parameters:
      kinematic - whether this dynamic body is treated as kinematic or not
    • isGrounded

      public boolean isGrounded()
      Gets whether or no this DynamicBodyComponent is considered grounded.
      Returns:
      true if this is grounded
    • setGrounded

      public void setGrounded(boolean grounded)
      Sets the grounded state.
      Parameters:
      grounded - the new grounded state
    • getMaterial

      public Material getMaterial()
      Gets the Material of this DynamicBodyComponent.
      Returns:
      this dynamic body's Material
    • setMaterial

      public void setMaterial(Material material)
      Change the Material used for this dynamic body.
      Parameters:
      material - the new Material