Module technology.sola.engine
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 Summary
ConstructorsConstructorDescriptionCreates a DynamicBodyComponent with aMaterial.UNIT_MASS_MATERIALMaterial.DynamicBodyComponent(boolean isKinematic) Creates a DynamicBodyComponent instance with a unit massMaterialand desired isKinematic value.DynamicBodyComponent(Material material) Creates a DynamicBodyComponent with desiredMaterial.DynamicBodyComponent(Material material, boolean isKinematic) Creates a DynamicBodyComponent with desiredMaterialand isKinematic value. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyForce(float forceX, float forceY) Apply a force to the dynamic body.voidapplyForce(Vector2D forceVector) Apply a force to the dynamic body.floatGets the force currently applied on the horizontal axis.floatGets the force currently applied on the vertical axis.Gets theMaterialof this DynamicBodyComponent.booleanGets whether or no this DynamicBodyComponent is considered grounded.booleanA kinematic dynamic body will not respond to external forces applied to it.voidsetForceX(float forceX) Sets the force on the horizontal axis.voidsetForceY(float forceY) Sets the force on the vertical axis.voidsetGrounded(boolean grounded) Sets the grounded state.voidsetKinematic(boolean kinematic) Updates the kinematic property for this dynamic body.voidsetMaterial(Material material) Change theMaterialused for this dynamic body.voidsetVelocity(Vector2D velocity) Sets the velocity for this dynamic body.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface technology.sola.ecs.Component
afterDeserialize
-
Constructor Details
-
DynamicBodyComponent
public DynamicBodyComponent()Creates a DynamicBodyComponent with aMaterial.UNIT_MASS_MATERIALMaterial. -
DynamicBodyComponent
Creates a DynamicBodyComponent with desiredMaterial.- Parameters:
material- theMaterialused
-
DynamicBodyComponent
public DynamicBodyComponent(boolean isKinematic) Creates a DynamicBodyComponent instance with a unit massMaterialand desired isKinematic value.- Parameters:
isKinematic- whether this dynamic body is treated as kinematic or not
-
DynamicBodyComponent
Creates a DynamicBodyComponent with desiredMaterialand isKinematic value.- Parameters:
material- theMaterialusedisKinematic- 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 axisforceY- force in vertical axis
-
applyForce
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
- Returns:
- the velocity of this dynamic body
-
setVelocity
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
Gets theMaterialof this DynamicBodyComponent.- Returns:
- this dynamic body's
Material
-
setMaterial
Change theMaterialused for this dynamic body.- Parameters:
material- the newMaterial
-