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_MATERIAL
Material
.DynamicBodyComponent
(boolean isKinematic) Creates a DynamicBodyComponent instance with a unit massMaterial
and desired isKinematic value.DynamicBodyComponent
(Material material) Creates a DynamicBodyComponent with desiredMaterial
.DynamicBodyComponent
(Material material, boolean isKinematic) Creates a DynamicBodyComponent with desiredMaterial
and isKinematic value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyForce
(float forceX, float forceY) Apply a force to the dynamic body.void
applyForce
(Vector2D forceVector) Apply a force to the dynamic body.float
Gets the force currently applied on the horizontal axis.float
Gets the force currently applied on the vertical axis.Gets theMaterial
of this DynamicBodyComponent.boolean
Gets whether or no this DynamicBodyComponent is considered grounded.boolean
A kinematic dynamic body will not respond to external forces applied to it.void
setForceX
(float forceX) Sets the force on the horizontal axis.void
setForceY
(float forceY) Sets the force on the vertical axis.void
setGrounded
(boolean grounded) Sets the grounded state.void
setKinematic
(boolean kinematic) Updates the kinematic property for this dynamic body.void
setMaterial
(Material material) Change theMaterial
used for this dynamic body.void
setVelocity
(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, wait
Methods inherited from interface technology.sola.ecs.Component
afterDeserialize
-
Constructor Details
-
DynamicBodyComponent
public DynamicBodyComponent()Creates a DynamicBodyComponent with aMaterial.UNIT_MASS_MATERIAL
Material
. -
DynamicBodyComponent
Creates a DynamicBodyComponent with desiredMaterial
.- Parameters:
material
- theMaterial
used
-
DynamicBodyComponent
public DynamicBodyComponent(boolean isKinematic) Creates a DynamicBodyComponent instance with a unit massMaterial
and desired isKinematic value.- Parameters:
isKinematic
- whether this dynamic body is treated as kinematic or not
-
DynamicBodyComponent
Creates a DynamicBodyComponent with desiredMaterial
and isKinematic value.- Parameters:
material
- theMaterial
usedisKinematic
- 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 theMaterial
of this DynamicBodyComponent.- Returns:
- this dynamic body's
Material
-
setMaterial
Change theMaterial
used for this dynamic body.- Parameters:
material
- the newMaterial
-