Class PhysicsBody
Hierarchy
- PhysicsBody
Index
Constructors
Properties
Accessors
Methods
- add
Constraint - apply
Force - apply
Impulse - clone
- compute
Mass Properties - dispose
- get
Angular Damping - get
Angular Velocity - get
Angular Velocity To Ref - get
Class Name - get
Collision Ended Observable - get
Collision Observable - get
Event Mask - get
Geometry - get
Gravity Factor - get
Linear Damping - get
Linear Velocity - get
Linear Velocity To Ref - get
Mass Properties - get
Motion Type - get
Object Center World - get
Object Center World To Ref - iterate
Over All Instances - set
Angular Damping - set
Angular Velocity - set
Collision Callback Enabled - set
Collision Ended Callback Enabled - set
Event Mask - set
Gravity Factor - set
Linear Damping - set
Linear Velocity - set
Mass Properties - set
Motion Type - set
Target Transform - sync
With Bone - update
Body Instances
Constructors
constructor
Constructs a new physics body for the given node.
Parameters
transformNode: TransformNode
The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.
motionType: PhysicsMotionType
The motion type of the physics body. The options are:
- PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.
- PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.
- PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.
startsAsleep: boolean
Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.
scene: Scene
The scene containing the physics engine.
This code is useful for creating a physics body for a given Transform Node in a scene. It checks the version of the physics engine and the physics plugin, and initializes the body accordingly. It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
Returns PhysicsBody
Properties
_plugin DataSearch playground for _pluginData
V2 Physics plugin private data for single Transform
_plugin Data InstancesSearch playground for _pluginDataInstances
V2 Physics plugin private data for instances
disable Pre StepSearch playground for disablePreStep
Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation. True by default for maximum performance.
start AsleepSearch playground for startAsleep
Physics engine will try to make this body sleeping and not active
transform NodeSearch playground for transformNode
The transform node associated with this Physics Body
Accessors
num Instances
This returns the number of internal instances of the physics body
Returns number
shape
Retrieves the physics shape associated with this object.
Returns Nullable<PhysicsShape>
The physics shape associated with this object, or
undefined
if no shape is associated.This method is useful for retrieving the physics shape associated with this object, which can be used to apply physical forces to the object or to detect collisions.
Sets the shape of the physics body.
Parameters
shape: Nullable<PhysicsShape>
The shape of the physics body.
This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior. The shape is used to calculate the body's mass, inertia, and other properties.
Returns void
Methods
add ConstraintSearch playground for addConstraint
Adds a constraint to the physics engine.
Parameters
childBody: PhysicsBody
The body to which the constraint will be applied.
constraint: PhysicsConstraint
The constraint to be applied.
Optional instanceIndex: number
If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.
Optional childInstanceIndex: number
If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.
Returns void
apply ForceSearch playground for applyForce
Applies a force to the physics object.
Parameters
force: Vector3
The force vector.
location: Vector3
The location of the force.
Optional instanceIndex: number
For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.
This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity, collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
Returns void
apply ImpulseSearch playground for applyImpulse
Applies an impulse to the physics object.
Parameters
impulse: Vector3
The impulse vector.
location: Vector3
The location of the impulse.
Optional instanceIndex: number
For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.
This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity, collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
Returns void
cloneSearch playground for clone
Clone the PhysicsBody to a new body and assign it to the transformNode parameter
Parameters
transformNode: TransformNode
transformNode that will be used for the cloned PhysicsBody
Returns PhysicsBody
the newly cloned PhysicsBody
compute Mass PropertiesSearch playground for computeMassProperties
Computes the mass properties of the physics object, based on the set of physics shapes this body uses. This method is useful for computing the initial mass properties of a physics object, such as its mass, inertia, and center of mass; these values are important for accurately simulating the physics of the object in the physics engine, and computing values based on the shape will provide you with reasonable intial values, which you can then customize.
Parameters
Optional instanceIndex: number
Returns PhysicsMassProperties
disposeSearch playground for dispose
Disposes the body from the physics engine.
This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.
Returns void
get Angular DampingSearch playground for getAngularDamping
Gets the angular damping of the physics body.
Parameters
Optional instanceIndex: number
Returns number
The angular damping of the physics body.
This method is useful for getting the angular damping of the physics body, which is the rate of reduction of the angular velocity over time. This is important for simulating realistic physics behavior in a game.
get Angular VelocitySearch playground for getAngularVelocity
Gets the angular velocity of the physics body as a new vector3.
Parameters
Optional instanceIndex: number
Returns Vector3
The angular velocity of the physics body.
This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's rotational speed. This information can be used to create realistic physics simulations.
get Angular Velocity To RefSearch playground for getAngularVelocityToRef
Gets the angular velocity of the physics body and stores it in the given vector3.
Parameters
angVel: Vector3
The vector3 to store the angular velocity in.
This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's rotational speed. This information can be used to create realistic physics simulations.
Optional instanceIndex: number
Returns void
get Class NameSearch playground for getClassName
Returns the string "PhysicsBody".
Returns string
"PhysicsBody"
get Collision Ended ObservableSearch playground for getCollisionEndedObservable
Returns an observable that will be notified when the body has finished colliding with another body
Returns Observable<IBasePhysicsCollisionEvent>
get Collision ObservableSearch playground for getCollisionObservable
Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody
Returns Observable<IPhysicsCollisionEvent>
Observable
get Event MaskSearch playground for getEventMask
Gets the event mask of the physics engine.
Parameters
Optional instanceIndex: number
Returns number
The event mask of the physics engine.
This method is useful for getting the event mask of the physics engine, which is used to determine which events the engine will respond to. This is important for ensuring that the engine is responding to the correct events and not wasting resources on unnecessary events.
get GeometrySearch playground for getGeometry
Retrieves the geometry of the body from the physics plugin.
Returns {}
The geometry of the body.
This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.
get Gravity FactorSearch playground for getGravityFactor
Gets the gravity factor of the physics body
Parameters
Optional instanceIndex: number
the instance of the body to get, if undefined the value of first instance will be returned
Returns number
the gravity factor
get Linear DampingSearch playground for getLinearDamping
Gets the linear damping of the physics body.
Parameters
Optional instanceIndex: number
Returns number
The linear damping of the physics body.
This method is useful for retrieving the linear damping of the physics body, which is the amount of resistance the body has to linear motion. This is useful for simulating realistic physics behavior in a game.
get Linear VelocitySearch playground for getLinearVelocity
Gets the linear velocity of the physics body as a new vector3.
Parameters
Optional instanceIndex: number
Returns Vector3
The linear velocity of the physics body.
This method is useful for getting the linear velocity of a physics body in a physics engine. This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.
get Linear Velocity To RefSearch playground for getLinearVelocityToRef
Gets the linear velocity of the physics body and stores it in the given vector3.
Parameters
linVel: Vector3
The vector3 to store the linear velocity in.
This method is useful for getting the linear velocity of a physics body in a physics engine. This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.
Optional instanceIndex: number
Returns void
get Mass PropertiesSearch playground for getMassProperties
Retrieves the mass properties of the object.
Parameters
Optional instanceIndex: number
Returns PhysicsMassProperties
The mass properties of the object.
This method is useful for physics simulations, as it allows the user to retrieve the mass properties of the object, such as its mass, center of mass, and moment of inertia. This information is necessary for accurate physics simulations.
get Motion TypeSearch playground for getMotionType
Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
Parameters
Optional instanceIndex: number
Returns PhysicsMotionType
get Object Center WorldSearch playground for getObjectCenterWorld
Parameters
Optional instanceIndex: number
Returns Vector3
get Object Center World To RefSearch playground for getObjectCenterWorldToRef
iterate Over All InstancesSearch playground for iterateOverAllInstances
Executes a callback on the body or all of the instances of a body
Parameters
callback: ((body: PhysicsBody, instanceIndex?: number) => void)
the callback to execute
Parameters
body: PhysicsBody
Optional instanceIndex: number
Returns void
Returns void
set Angular DampingSearch playground for setAngularDamping
Sets the angular damping of the physics body.
Parameters
damping: number
The angular damping of the body.
This method is useful for controlling the angular velocity of a physics body. By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction. This can be used to create realistic physical behavior in a physics engine.
Optional instanceIndex: number
Returns void
set Angular VelocitySearch playground for setAngularVelocity
Sets the angular velocity of the physics object.
Parameters
angVel: Vector3
The angular velocity to set.
This method is useful for setting the angular velocity of a physics object, which is necessary for simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object, which is important for simulating realistic motion.
Optional instanceIndex: number
Returns void
set Collision Callback EnabledSearch playground for setCollisionCallbackEnabled
Enable or disable collision callback for this PhysicsBody.
Parameters
enabled: boolean
true if PhysicsBody's collision will rise a collision event and notifies the observable
Returns void
set Collision Ended Callback EnabledSearch playground for setCollisionEndedCallbackEnabled
Parameters
enabled: boolean
Returns void
set Event MaskSearch playground for setEventMask
Sets the event mask for the physics engine.
Parameters
eventMask: number
A bitmask that determines which events will be sent to the physics engine.
This method is useful for setting the event mask for the physics engine, which determines which events will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
Optional instanceIndex: number
Returns void
set Gravity FactorSearch playground for setGravityFactor
Sets the gravity factor of the physics body
Parameters
factor: number
the gravity factor to set
Optional instanceIndex: number
the instance of the body to set, if undefined all instances will be set
Returns void
set Linear DampingSearch playground for setLinearDamping
Sets the linear damping of the physics body.
Parameters
damping: number
The linear damping value.
This method is useful for controlling the linear damping of the physics body, which is the rate at which the body's velocity decreases over time. This is useful for simulating the effects of air resistance or other forms of friction.
Optional instanceIndex: number
Returns void
set Linear VelocitySearch playground for setLinearVelocity
Sets the linear velocity of the physics object.
Parameters
linVel: Vector3
The linear velocity to set.
This method is useful for setting the linear velocity of a physics object, which is necessary for simulating realistic physics in a game engine. By setting the linear velocity, the physics object will move in the direction and speed specified by the vector. This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.
Optional instanceIndex: number
Returns void
set Mass PropertiesSearch playground for setMassProperties
Sets the mass properties of the physics object.
Parameters
massProps: PhysicsMassProperties
The mass properties to set.
Optional instanceIndex: number
The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.
This method is useful for setting the mass properties of a physics object, such as its mass, inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
Returns void
set Motion TypeSearch playground for setMotionType
Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
Parameters
motionType: PhysicsMotionType
Optional instanceIndex: number
Returns void
set Target TransformSearch playground for setTargetTransform
Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target
Parameters
position: Vector3
The target position
rotation: Quaternion
The target rotation
Optional instanceIndex: number
The index of the instance in an instanced body
Returns void
sync With BoneSearch playground for syncWithBone
Sync with a bone
Parameters
bone: Bone
The bone that the impostor will be synced to.
boneMesh: AbstractMesh
The mesh that the bone is influencing.
jointPivot: Vector3
The pivot of the joint / bone in local space.
Optional distToJoint: number
Optional distance from the impostor to the joint.
Optional adjustRotation: Quaternion
Optional quaternion for adjusting the local rotation of the bone.
Optional boneAxis: Vector3
Optional vector3 axis the bone is aligned with
Returns void
update Body InstancesSearch playground for updateBodyInstances
If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.
Returns void
PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows the user to set the mass and velocity of the body, which can then be used to calculate the motion of the body in the physics engine.