Photon Quantum 3.0.0

Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
Quantum.PhysicsBody2D Struct Reference

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...

Inheritance diagram for Quantum.PhysicsBody2D:
Quantum.IComponent

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...
 

Detailed Description

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.

Member Function Documentation

◆ GetInertia()

FP Quantum.PhysicsBody2D.GetInertia ( )
inline

Gets the physics body inertia, the resistance to changes in angular velocity.

◆ SetInertia()

void Quantum.PhysicsBody2D.SetInertia ( FP  inertia)
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.

◆ ResetInertia()

void Quantum.PhysicsBody2D.ResetInertia ( FrameBase  frame,
EntityRef  entity 
)
inline

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.

Parameters
frameCurrent frame instance in use.
entityThe entity from which the collider shape will be retrieved, necessary for computing the inertia.

◆ ResetCenterOfMass()

void Quantum.PhysicsBody2D.ResetCenterOfMass ( FrameBase  f,
EntityRef  entity 
)
inline

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.

Parameters
fCurrent frame instance in use.
entityThe entity from which the collider component and shape will be retrieved.

◆ AddLinearImpulse()

void Quantum.PhysicsBody2D.AddLinearImpulse ( FPVector2  amount,
FPVector2 relativePoint = null 
)
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.

Parameters
amountThe impulse vector to be applied.
relativePointA vector in world space that represents the distance from the center of mass to the point where the impulse is being applied.
See also
AddLinearImpulseAtPosition(Photon.Deterministic.FPVector2,Photon.Deterministic.FPVector2,Quantum.Transform2D)

◆ AddLinearImpulseAtPosition()

void Quantum.PhysicsBody2D.AddLinearImpulseAtPosition ( FPVector2  impulse,
FPVector2  position,
Transform2D transform 
)
inline

Applies the given linear impulse to the body at a given position in world space.

Parameters
impulseThe impulse vector to be applied.
positionThe point in world space where the impulse is being applied. This position should be withing the collider shape in order to prevent unrealistic behavior.
transformThe current transform of the entity that owns this physics body.

◆ AddAngularImpulse()

void Quantum.PhysicsBody2D.AddAngularImpulse ( FP  amount)
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.

Parameters
amountThe angular impulse to be applied.

◆ ClearForce()

void Quantum.PhysicsBody2D.ClearForce ( )
inline

Clears all the accumulated forces in this body.

◆ AddForce()

void Quantum.PhysicsBody2D.AddForce ( FPVector2  amount,
FPVector2 relativePoint = null 
)
inline

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.

Parameters
amountThe force vector in world coordinates.
relativePointA vector in world space that represents the distance from the center of mass to the point where the impulse is being applied.
See also
AddTorque

◆ AddForceAtPosition()

void Quantum.PhysicsBody2D.AddForceAtPosition ( FPVector2  force,
FPVector2  position,
Transform2D transform 
)
inline

Applies the given force to the body at a given position in world space.

Parameters
forceThe force vector to be applied.
positionThe point in world space where the impulse is being applied. This position should be withing the collider shape in order to prevent unrealistic behavior.
transformThe current transform of the entity that owns this physics body.

◆ ClearTorque()

void Quantum.PhysicsBody2D.ClearTorque ( )
inline

Clears all the accumulated torques in this body.

◆ AddTorque()

void Quantum.PhysicsBody2D.AddTorque ( FP  amount)
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.

Parameters
amountThe torque to be accumulated.

◆ GetPointVelocity()

FPVector2 Quantum.PhysicsBody2D.GetPointVelocity ( FPVector2  point,
Transform2D bodyTransform 
)
inline

Computes the velocity of the physics body at a given point defined in world space.

Parameters
pointThe point where the velocity will be computed at, in world space.
bodyTransformThe transform component of the entity to which this physics body belongs.
Returns
A 2D vector representing the computed velocity, also in world space.

◆ GetRelativePointVelocity()

FPVector2 Quantum.PhysicsBody2D.GetRelativePointVelocity ( FPVector2  point,
Transform2D bodyTransform 
)
inline

Computes the velocity of the physics body at a given point defined on its local space.

Parameters
pointThe point where the velocity will be computed at, in local space.
bodyTransformThe transform component of the entity to which this physics body belongs.
Returns
A 2D vector representing the computed velocity, in world space.

◆ WakeUp()

void Quantum.PhysicsBody2D.WakeUp ( )
inline

Wakes up a sleeping physics body and resets the accumulated time within sleeping thresholds.

◆ Sleep()

void Quantum.PhysicsBody2D.Sleep ( )
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.

◆ Serialize()

static void Quantum.PhysicsBody2D.Serialize ( void *  ptr,
FrameSerializer  serializer 
)
inlinestatic

Serializes a PhysicsBody2D into a FrameSerializer.

Parameters
ptrThe pointer to the PhysicsBody2D.
serializerThe FrameSerializer instance into which the struct will be serialized.

Member Data Documentation

◆ SIZE

const int Quantum.PhysicsBody2D.SIZE = FIRST_FPVECTOR2_OFFSET + FPVector2.SIZE * 4
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.

◆ AngularVelocity

FP Quantum.PhysicsBody2D.AngularVelocity

The rate of change of physics rotation in radians per second.

◆ Velocity

FPVector2 Quantum.PhysicsBody2D.Velocity

The rate of change of physics body position in units per second.

◆ CenterOfMass

FPVector2 Quantum.PhysicsBody2D.CenterOfMass

The center of mass position relative to the transform's origin.

Property Documentation

◆ Force

FPVector2 Quantum.PhysicsBody2D.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.

◆ Torque

FP Quantum.PhysicsBody2D.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.

◆ Enabled

Boolean? Quantum.PhysicsBody2D.Enabled
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.

◆ AllowSleeping

Boolean? Quantum.PhysicsBody2D.AllowSleeping
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.

◆ IsAwakenedByKinematics

Boolean? Quantum.PhysicsBody2D.IsAwakenedByKinematics
getset

Allows sleeping physic bodies to be awakened when interacting with other colliders or kinematic bodies.

◆ IsSleeping

Boolean Quantum.PhysicsBody2D.IsSleeping
get

Returns true if the object is sleeping.

◆ Drag

FP Quantum.PhysicsBody2D.Drag
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;

◆ AngularDrag

FP Quantum.PhysicsBody2D.AngularDrag
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;

◆ FreezeRotation

Boolean? Quantum.PhysicsBody2D.FreezeRotation
getset

Prevents the physics update to apply changes to the rotation of the physics body.

◆ UseContinuousCollisionDetection

Boolean? Quantum.PhysicsBody2D.UseContinuousCollisionDetection
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.

◆ Mass

FP Quantum.PhysicsBody2D.Mass
getset

The value of the body mass property. If zero, the physics body becomes kinematic body.

◆ MassInverse

FP Quantum.PhysicsBody2D.MassInverse
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.

◆ GravityScale

FP Quantum.PhysicsBody2D.GravityScale
getset

The multiplier for the gravity force applied at this physics body.

◆ IsKinematic

Boolean? Quantum.PhysicsBody2D.IsKinematic
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.