Adds physics motion to an entity with a PhysicsCollider2D driven by the built-in physics systems. You can customize how the movement of the physics body will works by changing the Mass, GravityScale or Drag. A Kinematic body will not have linear and angular velocities integrated, but those values are still perceived and taken into account when resolving the collision with other dynamic bodies. More...
Public Types | |
enum | ConfigFlags : byte |
The flags to set up how the physics body will behave in the physics systems. More... | |
Public Member Functions | |
void | AddAngularImpulse (FP amount) |
Applies the given amount of angular impulse to the body. The amount of delta angular velocity generated by the angular impulse is inversely proportional to the inertia of the body. More... | |
void | AddForce (FPVector2 amount, FPVector2? relativePoint=null) |
Increases the Force value with the amount vector. The force is integrated into delta velocity on the next Physics Update. The amount of delta-velocity produced by the accumulated force is directly proportional do the delta-time and inversely proportional do the Mass of the body. If the impulse is applied at a relativePoint that is different than zero, it will also generate Torque. More... | |
void | AddForceAtPosition (FPVector2 force, FPVector2 position, Transform2D *transform) |
Applies the given force to the body at a given position in world space. More... | |
void | AddForceAtPosition (FPVector2 force, FPVector2 position, Transform2D transform) |
void | AddLinearImpulse (FPVector2 amount, FPVector2? relativePoint=null) |
Applies the given amount of linear impulse to the body. The amount of delta-velocity generated by the impulse is inversely proportional to the mass of the body. If the impulse is applied in a relativePoint that is different than zero, it will also generate a delta angular velocity. More... | |
void | AddLinearImpulseAtPosition (FPVector2 impulse, FPVector2 position, Transform2D *transform) |
Applies the given linear impulse to the body at a given position in world space. More... | |
void | AddLinearImpulseAtPosition (FPVector2 impulse, FPVector2 position, Transform2D transform) |
void | AddTorque (FP amount) |
Accumulates a given amount of torque, to be integrated into angular velocity on the next Physics Update. The amount of delta angular velocity produced by the angular impulse is directly proportional to the Update delta-time and inversely proportional to the body inertia on each axis. More... | |
void | ClearForce () |
Clears all the accumulated forces in this body. More... | |
void | ClearTorque () |
Clears all the accumulated torques in this body. More... | |
FP | GetInertia () |
Gets the physics body inertia, the resistance to changes in angular velocity. More... | |
FPVector2 | GetPointVelocity (FPVector2 point, Transform2D *bodyTransform) |
Computes the velocity of the physics body at a given point defined in world space. More... | |
FPVector2 | GetRelativePointVelocity (FPVector2 point, Transform2D *bodyTransform) |
Computes the velocity of the physics body at a given point defined on its local space. More... | |
void | InitBody (FP bodyMass, FP drag, FP angularDrag, ConfigFlags bodyConfig, FPVector2? centerOfMass=null, NullableFP gravityScale=default) |
Initializes a PhysicsBody2D component with custom settings. More... | |
void | ResetCenterOfMass (FrameBase f, EntityRef entity) |
Resets the CenterOfMass of physics body component to the shape Shape2D.Centroid of a PhysicsCollider2D component attached to the entity . More... | |
void | ResetInertia (FrameBase frame, EntityRef entity) |
Resets the inertia on this physics body component based on its mass and the shape of a PhysicsCollider2D component on the entity . More... | |
void | SetInertia (FP inertia) |
Sets the inertia value. More... | |
void | Sleep () |
Puts an enabled physics body into a sleeping state. More... | |
void | WakeUp () |
Wakes up a sleeping physics body and resets the accumulated time within sleeping thresholds. More... | |
Static Public Member Functions | |
static PhysicsBody2D | CreateDynamic (FP mass, FP drag, FP angularDrag, Boolean allowSleeping, Boolean awakenByKinematics=false, Boolean freezeRotation=false, FPVector2? centerOfMass=null, NullableFP gravityScale=default) |
Creates a dynamic PhysicsBody2D. More... | |
static PhysicsBody2D | CreateDynamic (FP mass, FP drag=default, FP angularDrag=default, ConfigFlags bodyConfig=ConfigFlags.Default, FPVector2? centerOfMass=null, NullableFP gravityScale=default) |
static PhysicsBody2D | CreateKinematic () |
Creates a kinematic PhysicsBody2D. The mass, drag and angular drag are not considered in kinematic interactions and have 0 as value. More... | |
static void | Serialize (void *ptr, FrameSerializer serializer) |
Serializes a PhysicsBody2D into a FrameSerializer. More... | |
Public Attributes | |
FP | AngularVelocity |
The rate of change of physics rotation in radians per second. More... | |
FPVector2 | CenterOfMass |
The center of mass position relative to the transform's origin. More... | |
FPVector2 | Velocity |
The rate of change of physics body position in units per second. More... | |
Static Public Attributes | |
const int | SIZE = FIRST_FPVECTOR2_OFFSET + FPVector2.SIZE * 4 |
The size of the component (or struct/type) in-memory inside the Frame data-buffers or stack (when passed as value parameter). Not related to the snapshot payload this occupies, which is bit-packed and compressed. More... | |
Properties | |
Boolean? | AllowSleeping [get, set] |
Allows the physics body to sleep after some time at rest. When sleeping, it will not integrate the velocity until other forces awaken it. See PhysicsSceneSettings to setup the time to sleep and the tolerances for linear and angular velocity. More... | |
FP | AngularDrag [get, set] |
The rate of angular velocity that the physics body will lose per second. The higher the drag, the faster the object slows down. Angular Drag affects angular velocity every frame according to the following pseudo-code: More... | |
FP | Drag [get, set] |
The rate of linear velocity that the physics body will lose per second. The higher the drag, the faster the object slows down. Drag affects velocity every frame according to the following pseudo-code: More... | |
Boolean? | Enabled [get, set] |
If this physics body component should be taken into consideration by the physics engine. If false, the entity will have as if not having a physics body component. More... | |
FPVector2 | Force [get] |
The accumulated forces by the AddForce method that will be integrated into delta velocity on the next Physics Update. This value is reset after the integration. More... | |
Boolean? | FreezeRotation [get, set] |
Prevents the physics update to apply changes to the rotation of the physics body. More... | |
FP | GravityScale [get, set] |
The multiplier for the gravity force applied at this physics body. More... | |
Boolean? | IsAwakenedByKinematics [get, set] |
Allows sleeping physic bodies to be awakened when interacting with other colliders or kinematic bodies. More... | |
Boolean? | IsKinematic [get, set] |
Prevents the physics update integrating the linear and angular velocities of this physics body. Other non-kinematic body in contact with this physics body will still take those velocities into consideration. More... | |
Boolean | IsSleeping [get] |
Returns true if the object is sleeping. More... | |
FP | Mass [get, set] |
The value of the body mass property. If zero, the physics body becomes kinematic body. More... | |
FP | MassInverse [get, set] |
The inverse value of the body mass property (1/mass). The inverse mass value is what is stored internally on the component, so accessing or modifying this value directly instead of through the regular Mass can prevent inaccuracies from being introduced in the conversion of values. More... | |
FP | Torque [get] |
The accumulated torques by the AddTorque method that will be integrated into delta angular velocity on the next Physics Update. This value is reset after the integration. More... | |
Boolean? | UseContinuousCollisionDetection [get, set] |
Prevents the physics body from passing through other objects when at high velocity. More... | |
Adds physics motion to an entity with a PhysicsCollider2D driven by the built-in physics systems. You can customize how the movement of the physics body will works by changing the Mass, GravityScale or Drag. A Kinematic body will not have linear and angular velocities integrated, but those values are still perceived and taken into account when resolving the collision with other dynamic bodies.
|
inline |
Gets the physics body inertia, the resistance to changes in angular velocity.
|
inline |
Sets the inertia value.
The inertia value is computed automatically when it is attached to an entity and the flag ConfigFlags.ResetInertiaOnAdded is set. The value is based on the shape and mass of the body.
Resets the inertia on this physics body component based on its mass and the shape of a PhysicsCollider2D component on the entity .
This is called automatically when a PhysicsBody2D component is added to an entity, unless the body ConfigFlags.ResetInertiaOnAdded flag is not set. The body's center of mass affects the computation of the inertia, so consider calling ResetCenterOfMass before resetting the inertia, specially if the collider shape has changed. More info on the online docs here.
frame | Current frame instance in use. |
entity | The entity from which the collider shape will be retrieved, necessary for computing the inertia. |
Resets the CenterOfMass of physics body component to the shape Shape2D.Centroid of a PhysicsCollider2D component attached to the entity .
This is called automatically when a PhysicsBody2D component is added to an entity, unless the body ConfigFlags.ResetCenterOfMassOnAdded flag is not set. When changing the collider shape in runtime, consider resetting the center of mass and inertia of the attached physics body, in this order. More info on the online docs here.
f | Current frame instance in use. |
entity | The entity from which the collider component and shape will be retrieved. |
|
inline |
Applies the given amount of linear impulse to the body. The amount of delta-velocity generated by the impulse is inversely proportional to the mass of the body. If the impulse is applied in a relativePoint that is different than zero, it will also generate a delta angular velocity.
amount | The impulse vector to be applied. |
relativePoint | A vector in world space that represents the distance from the center of mass to the point where the impulse is being applied. |
|
inline |
Applies the given linear impulse to the body at a given position in world space.
impulse | The impulse vector to be applied. |
position | The point in world space where the impulse is being applied. This position should be withing the collider shape in order to prevent unrealistic behavior. |
transform | The current transform of the entity that owns this physics body. |
|
inline |
Applies the given amount of angular impulse to the body. The amount of delta angular velocity generated by the angular impulse is inversely proportional to the inertia of the body.
amount | The angular impulse to be applied. |
|
inline |
Clears all the accumulated forces in this body.
Increases the Force value with the amount vector. The force is integrated into delta velocity on the next Physics Update. The amount of delta-velocity produced by the accumulated force is directly proportional do the delta-time and inversely proportional do the Mass of the body. If the impulse is applied at a relativePoint that is different than zero, it will also generate Torque.
amount | The force vector in world coordinates. |
relativePoint | A vector in world space that represents the distance from the center of mass to the point where the impulse is being applied. |
|
inline |
Applies the given force to the body at a given position in world space.
force | The force vector to be applied. |
position | The point in world space where the impulse is being applied. This position should be withing the collider shape in order to prevent unrealistic behavior. |
transform | The current transform of the entity that owns this physics body. |
|
inline |
Clears all the accumulated torques in this body.
|
inline |
Accumulates a given amount of torque, to be integrated into angular velocity on the next Physics Update. The amount of delta angular velocity produced by the angular impulse is directly proportional to the Update delta-time and inversely proportional to the body inertia on each axis.
amount | The torque to be accumulated. |
|
inline |
Computes the velocity of the physics body at a given point defined in world space.
point | The point where the velocity will be computed at, in world space. |
bodyTransform | The transform component of the entity to which this physics body belongs. |
|
inline |
Computes the velocity of the physics body at a given point defined on its local space.
point | The point where the velocity will be computed at, in local space. |
bodyTransform | The transform component of the entity to which this physics body belongs. |
|
inline |
Wakes up a sleeping physics body and resets the accumulated time within sleeping thresholds.
|
inline |
Puts an enabled physics body into a sleeping state.
If set during a physics collision callback, the body might be awakened by the solver if the collision is not ignored.
|
inlinestatic |
Serializes a PhysicsBody2D into a FrameSerializer.
ptr | The pointer to the PhysicsBody2D. |
serializer | The FrameSerializer instance into which the struct will be serialized. |
|
static |
The size of the component (or struct/type) in-memory inside the Frame data-buffers or stack (when passed as value parameter). Not related to the snapshot payload this occupies, which is bit-packed and compressed.
FP Quantum.PhysicsBody2D.AngularVelocity |
The rate of change of physics rotation in radians per second.
FPVector2 Quantum.PhysicsBody2D.Velocity |
The rate of change of physics body position in units per second.
FPVector2 Quantum.PhysicsBody2D.CenterOfMass |
The center of mass position relative to the transform's origin.
|
get |
The accumulated forces by the AddForce method that will be integrated into delta velocity on the next Physics Update. This value is reset after the integration.
|
get |
The accumulated torques by the AddTorque method that will be integrated into delta angular velocity on the next Physics Update. This value is reset after the integration.
|
getset |
If this physics body component should be taken into consideration by the physics engine. If false, the entity will have as if not having a physics body component.
|
getset |
Allows the physics body to sleep after some time at rest. When sleeping, it will not integrate the velocity until other forces awaken it. See PhysicsSceneSettings to setup the time to sleep and the tolerances for linear and angular velocity.
|
getset |
Allows sleeping physic bodies to be awakened when interacting with other colliders or kinematic bodies.
|
get |
Returns true if the object is sleeping.
|
getset |
The rate of linear velocity that the physics body will lose per second. The higher the drag, the faster the object slows down. Drag affects velocity every frame according to the following pseudo-code:
Velocity *= FP._1 - Drag * deltaTime;
|
getset |
The rate of angular velocity that the physics body will lose per second. The higher the drag, the faster the object slows down. Angular Drag affects angular velocity every frame according to the following pseudo-code:
AngularVelocity *= FP._1 - AngularDrag * deltaTime;
|
getset |
Prevents the physics update to apply changes to the rotation of the physics body.
|
getset |
Prevents the physics body from passing through other objects when at high velocity.
The Continuous Collision Detection uses the GJK algorithm to check the distance between the objects. See CCDSettings to update the settings and improve the collision detection or performance.
|
getset |
The value of the body mass property. If zero, the physics body becomes kinematic body.
|
getset |
The inverse value of the body mass property (1/mass). The inverse mass value is what is stored internally on the component, so accessing or modifying this value directly instead of through the regular Mass can prevent inaccuracies from being introduced in the conversion of values.
|
getset |
The multiplier for the gravity force applied at this physics body.
|
getset |
Prevents the physics update integrating the linear and angular velocities of this physics body. Other non-kinematic body in contact with this physics body will still take those velocities into consideration.