Enfusion Script API
Loading...
Searching...
No Matches
Physics Interface Reference

Wrapper over a physics simulation of an entity. More...

Inheritance diagram for Physics:
NativeComponent pointer

Public Member Functions

proto external void Destroy ()
 Destroys the physics body.
 
proto external void SetInteractionLayer (int mask)
 Sets interaction layer mask of the physics body.
 
proto external void GetWorldTransform (out vector mat[4])
 Returns world space transformation of the physics body (including scale).
 
proto external void GetDirectWorldTransform (out vector mat[4])
 Returns internal world space transformation of the physics body (excluding scale).
 
proto external void SetGeomInteractionLayer (int index, int mask)
 Sets interaction layer mask of the geometry element.
 
proto external int GetInteractionLayer ()
 Returns interaction layer mask of the physics body.
 
proto external bool HasInteractionEnabled (int mask)
 Returns true if the physics body has enabled interaction with other body's layer mask.
 
proto external int GetGeomInteractionLayer (int index)
 Returns interaction layer mask of the geometry element.
 
proto external void EnableCCD (float maxMotion, float sphereCastRadius)
 Changes state of the continuous collision detection (CCD).
 
proto external void ChangeSimulationState (SimulationState simState)
 Changes simulation state of the physics body.
 
proto external SimulationState GetSimulationState ()
 Returns simulation state of the physics body.
 
proto external vector GetCenterOfMass ()
 Returns center of mass offset of the physics body.
 
proto external void SetActive (ActiveState act)
 Changes activation state of the physics body.
 
proto external bool IsActive ()
 Returns whether the physics body is being simulated (awake).
 
proto external bool IsDynamic ()
 Returns whether the physics body is dynamic (a rigid body).
 
proto external bool IsKinematic ()
 Returns whether the physics body is kinematic (animated)
 
proto external bool EnableGravity (bool enable)
 Enables gravity on the physics body.
 
proto external void SetDamping (float linearDamping, float angularDamping)
 Changes damping parameters of the physics body.
 
proto external float GetMass ()
 Returns mass of the physics body.
 
proto external void SetMass (float mass)
 Changes mass of the physics body.
 
proto external void SetInertiaTensorV (vector v)
 Changes inertia tensor of the physics body.
 
proto external vector GetAngularVelocity ()
 Returns angular velocity of the physics body.
 
proto external vector GetVelocityAt (vector pos)
 Returns linear velocity of the physics body at a position (world space coordinates).
 
proto external void SetSleepingTreshold (float linearTreshold, float angularTreshold)
 Changes thresholds used to determine whether the physics body can stop simulation.
 
proto external void SetLinearFactor (vector linearFactor)
 Sets scale factor for all impulses/velocities/forces. Default is <1,1,1>. Zero any axis if you want to do 2D physics.
 
proto external vector GetVelocity ()
 Returns linear velocity of the physics body.
 
proto external void SetVelocity (vector velocity)
 Sets linear velocity of the physics body.
 
proto external void SetAngularVelocity (vector velocity)
 Sets angular velocity of the physics body.
 
proto external void SetTargetMatrix (vector matrix[4], float timeslice)
 Sets target transformation.
 
proto external void ApplyImpulse (vector impulse)
 Applies impulse on the physics body.
 
proto external void ApplyImpulseAt (vector pos, vector impulse)
 Applies impulse on the physics body at a position (world space coordinates).
 
proto external void ApplyForce (vector force)
 Applies constant force on the physics body (at origin).
 
proto external void ApplyForceAt (vector pos, vector force)
 Applies constant force on the physics body at a position (world space coordinates).
 
proto external void ApplyTorque (vector torque)
 Applies constant torque on the physics body.
 
proto external void ClearForces ()
 Clear forces and torques on the physics body.
 
proto external vector GetTotalForce ()
 Returns total force currently applied to the physics body.
 
proto external vector GetTotalTorque ()
 Returns total torque currently applied to the physics body.
 
proto external void SetResponseIndex (int responseIndex)
 Changes index to response matrix, see "project settings/physics/interactions/response matrix".
 
proto external int GetResponseIndex ()
 Returns actual index to response matrix.
 
proto external int AddGeom (string name, PhysicsGeom geom, vector frame[4], string material, int interactionLayer)
 Adds new geometry and returns an index of the geometry or -1 when an error occurred.
 
proto external int GetGeom (string name)
 Finds a geometry by its name and returns its index or -1 if the geometry wasn't found.
 
proto external int GetNumGeoms ()
 Returns number of geometries of the entity.
 
proto external bool UpdateGeometries (int interactionLayerAnd=0xffffffff, int interactionLayerOr=0)
 Returns world space transformation of a geometry element.
 
proto external void GetGeomWorldTransform (int index, out vector mat[4])
 Returns world space transformation of a geometry element.
 
proto external void GetGeomTransform (int index, out vector mat[4])
 Returns entity space transformation of a geometry element.
 
proto external void GetGeomDirectTransform (int index, out vector mat[4])
 Returns internal physics space transformation of a geometry element.
 
proto external vector GetGeomWorldPosition (int index)
 Returns world space position of a geometry element.
 
proto external vector GetGeomPosition (int index)
 Returns entity space position of a geometry element.
 
proto external vector GetGeomDirectPosition (int index)
 Returns internal physics space position of a geometry element.
 
proto external void GetGeomWorldBounds (int index, out vector min, out vector max)
 Returns world bounds of a geometry element.
 
proto external void GetGeomDirectBounds (int index, out vector min, out vector max)
 Returns internal physics bounds of a geometry element (at scale 1)
 
proto external void GetGeomSurfaces (int index, notnull out array< SurfaceProperties > surfaces)
 Returns all surface properties of a geometry element.
 
- Public Member Functions inherited from pointer
proto string ToString ()
 

Static Public Member Functions

static proto Physics CreateStatic (notnull IEntity ent, int layerMask=0xffffffff)
 Creates a static physics body from geometry embedded in attached VObject.
 
static proto Physics CreateStaticEx (notnull IEntity ent, PhysicsGeomDef geoms[])
 Creates a static physics body from custom made geometries.
 
static proto Physics CreateDynamic (notnull IEntity ent, float mass, int layerMask=0xffffffff)
 Creates a dynamic physics body from geometry embedded in attached VObject.
 
static proto Physics CreateDynamicEx (notnull IEntity ent, vector centerOfMass, float mass, PhysicsGeomDef geoms[])
 Creates a dynamic physics body from custom made geometries.
 
static proto Physics CreateGhostEx (notnull IEntity ent, PhysicsGeomDef geoms[])
 Creates a ghost physics body from custom made geometries.
 

Static Public Attributes

static const float KMH2MS = 1 / 3.6
 
static const float MS2KMH = 3.6
 
static const float STANDARD_GRAVITY = 9.81
 
static const vector VGravity = "0 -9.81 0"
 

Detailed Description

Wrapper over a physics simulation of an entity.

The entity is capable of the physics simulation only when such object exists (see IEntity.GetPhysics). Two main types of physics bodies are static and dynamic. Static bodies are represented by a collision object and dynamic bodies by a rigid body. This means certain methods make sense only when dealing with a dynamic physics body, e.g., Physics.GetVelocity, Physics.ApplyImpulse.

Physics bodies rely on physics geometries to support collisions or casting. In general a physics body can be made out of multiply physics geometries. Certain methods allow to work with a specific physics geometry (via geometry index).

Member Function Documentation

◆ AddGeom()

proto external int Physics.AddGeom ( string name,
PhysicsGeom geom,
vector frame[4],
string material,
int interactionLayer )

Adds new geometry and returns an index of the geometry or -1 when an error occurred.

vector frame[4];
frame[3] = vector.Up;
string material = "{D745FD8FC67DB26A}Common/Materials/Game/stone.gamemat";
GetPhysics().AddGeom("Box", geom, frame, material, 0xffffffff);
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
Definition Math3D.c:13
static proto void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Geometric shapes relevant for physics simulation.
Definition PhysicsGeom.c:16
static proto PhysicsGeom CreateBox(vector size)
Creates box geometry.
Definition vector.c:13
static const vector Up
Definition vector.c:17
Parameters
nameName of the element
geomPhysics geometry shape
frameLocal transformation
materialMaterial resource name
interactionLayerBit mask of layers geometry belongs to

◆ ApplyForce()

proto external void Physics.ApplyForce ( vector force)

Applies constant force on the physics body (at origin).

◆ ApplyForceAt()

proto external void Physics.ApplyForceAt ( vector pos,
vector force )

Applies constant force on the physics body at a position (world space coordinates).

◆ ApplyImpulse()

proto external void Physics.ApplyImpulse ( vector impulse)

Applies impulse on the physics body.

◆ ApplyImpulseAt()

proto external void Physics.ApplyImpulseAt ( vector pos,
vector impulse )

Applies impulse on the physics body at a position (world space coordinates).

◆ ApplyTorque()

proto external void Physics.ApplyTorque ( vector torque)

Applies constant torque on the physics body.

◆ ChangeSimulationState()

proto external void Physics.ChangeSimulationState ( SimulationState simState)

Changes simulation state of the physics body.

◆ ClearForces()

proto external void Physics.ClearForces ( )

Clear forces and torques on the physics body.

◆ CreateDynamic()

static proto Physics Physics.CreateDynamic ( notnull IEntity ent,
float mass,
int layerMask = 0xffffffff )
static

Creates a dynamic physics body from geometry embedded in attached VObject.

If there is not any, false is returned.

Parameters
entEntity that will be associated with the physics body
massBody mass
layerMaskBit mask of layers that is ANDed with layers in object geometry. Use 0xffffffff if you want to keep it unmodified

◆ CreateDynamicEx()

static proto Physics Physics.CreateDynamicEx ( notnull IEntity ent,
vector centerOfMass,
float mass,
PhysicsGeomDef geoms[] )
static

Creates a dynamic physics body from custom made geometries.

The geometries are deleted when rigid body is destroyed.

string material = "{D745FD8FC67DB26A}Common/Materials/Game/stone.gamemat";
PhysicsGeomDef geoms[] = { PhysicsGeomDef("", geom, material, 0xffffffff) };
vector center = 2 * vector.Up;
Physics.CreateDynamicEx(this, center, 1.0, geoms);
Geometry element properties.
Definition PhysicsGeomDef.c:16
Wrapper over a physics simulation of an entity.
Definition Physics.c:22
static proto Physics CreateDynamicEx(notnull IEntity ent, vector centerOfMass, float mass, PhysicsGeomDef geoms[])
Creates a dynamic physics body from custom made geometries.
Parameters
entEntity that will be associated with the physics body
centerOfMassOffset from object-pivot to center of mass
massBody mass
geomsArray of custom made geometries

◆ CreateGhostEx()

static proto Physics Physics.CreateGhostEx ( notnull IEntity ent,
PhysicsGeomDef geoms[] )
static

Creates a ghost physics body from custom made geometries.

The geometries are deleted when rigid body is destroyed.

Parameters
entEntity that will be associated with the physics body
geomsArray of custom made geometries

◆ CreateStatic()

static proto Physics Physics.CreateStatic ( notnull IEntity ent,
int layerMask = 0xffffffff )
static

Creates a static physics body from geometry embedded in attached VObject.

If there is not any, false is returned.

Parameters
entEntity that will be associated with the physics body
layerMaskBit mask of layers that is ANDed with layers in object geometry. Use 0xffffffff if you want to keep it unmodified

◆ CreateStaticEx()

static proto Physics Physics.CreateStaticEx ( notnull IEntity ent,
PhysicsGeomDef geoms[] )
static

Creates a static physics body from custom made geometries.

The geometries are deleted when rigid body is destroyed.

string material = "{D745FD8FC67DB26A}Common/Materials/Game/stone.gamemat";
PhysicsGeomDef geoms[] = { PhysisGeomDef("Box", geom, material, 0xffffffff) };
Physics.CreateStaticEx(this, geoms);
static proto Physics CreateStaticEx(notnull IEntity ent, PhysicsGeomDef geoms[])
Creates a static physics body from custom made geometries.
Parameters
entEntity that will be associated with the physics body
geomsArray of custom made geometries

◆ Destroy()

proto external void Physics.Destroy ( )

Destroys the physics body.

◆ EnableCCD()

proto external void Physics.EnableCCD ( float maxMotion,
float sphereCastRadius )

Changes state of the continuous collision detection (CCD).

If both maxMotion and shapeCastRadius is >=0 then the CCD is enabled. If you want to disable it, use -1.

Parameters
maxMotionMax motion threshold when sphere-cast is performed, to find time of impact. It should be little bit less than size of the geometry to catch the situation when tunneling can happen.
sphereCastRadiusThe radius of the largest possible sphere, that is completely inside the body geometry.

◆ EnableGravity()

proto external bool Physics.EnableGravity ( bool enable)

Enables gravity on the physics body.

◆ GetAngularVelocity()

proto external vector Physics.GetAngularVelocity ( )

Returns angular velocity of the physics body.

◆ GetCenterOfMass()

proto external vector Physics.GetCenterOfMass ( )

Returns center of mass offset of the physics body.

◆ GetDirectWorldTransform()

proto external void Physics.GetDirectWorldTransform ( out vector mat[4])

Returns internal world space transformation of the physics body (excluding scale).

◆ GetGeom()

proto external int Physics.GetGeom ( string name)

Finds a geometry by its name and returns its index or -1 if the geometry wasn't found.

◆ GetGeomDirectBounds()

proto external void Physics.GetGeomDirectBounds ( int index,
out vector min,
out vector max )

Returns internal physics bounds of a geometry element (at scale 1)

◆ GetGeomDirectPosition()

proto external vector Physics.GetGeomDirectPosition ( int index)

Returns internal physics space position of a geometry element.

◆ GetGeomDirectTransform()

proto external void Physics.GetGeomDirectTransform ( int index,
out vector mat[4] )

Returns internal physics space transformation of a geometry element.

◆ GetGeomInteractionLayer()

proto external int Physics.GetGeomInteractionLayer ( int index)

Returns interaction layer mask of the geometry element.

◆ GetGeomPosition()

proto external vector Physics.GetGeomPosition ( int index)

Returns entity space position of a geometry element.

◆ GetGeomSurfaces()

proto external void Physics.GetGeomSurfaces ( int index,
notnull out array< SurfaceProperties > surfaces )

Returns all surface properties of a geometry element.

◆ GetGeomTransform()

proto external void Physics.GetGeomTransform ( int index,
out vector mat[4] )

Returns entity space transformation of a geometry element.

◆ GetGeomWorldBounds()

proto external void Physics.GetGeomWorldBounds ( int index,
out vector min,
out vector max )

Returns world bounds of a geometry element.

◆ GetGeomWorldPosition()

proto external vector Physics.GetGeomWorldPosition ( int index)

Returns world space position of a geometry element.

◆ GetGeomWorldTransform()

proto external void Physics.GetGeomWorldTransform ( int index,
out vector mat[4] )

Returns world space transformation of a geometry element.

◆ GetInteractionLayer()

proto external int Physics.GetInteractionLayer ( )

Returns interaction layer mask of the physics body.

◆ GetMass()

proto external float Physics.GetMass ( )

Returns mass of the physics body.

◆ GetNumGeoms()

proto external int Physics.GetNumGeoms ( )

Returns number of geometries of the entity.

◆ GetResponseIndex()

proto external int Physics.GetResponseIndex ( )

Returns actual index to response matrix.

◆ GetSimulationState()

proto external SimulationState Physics.GetSimulationState ( )

Returns simulation state of the physics body.

◆ GetTotalForce()

proto external vector Physics.GetTotalForce ( )

Returns total force currently applied to the physics body.

◆ GetTotalTorque()

proto external vector Physics.GetTotalTorque ( )

Returns total torque currently applied to the physics body.

◆ GetVelocity()

proto external vector Physics.GetVelocity ( )

Returns linear velocity of the physics body.

◆ GetVelocityAt()

proto external vector Physics.GetVelocityAt ( vector pos)

Returns linear velocity of the physics body at a position (world space coordinates).

◆ GetWorldTransform()

proto external void Physics.GetWorldTransform ( out vector mat[4])

Returns world space transformation of the physics body (including scale).

◆ HasInteractionEnabled()

proto external bool Physics.HasInteractionEnabled ( int mask)

Returns true if the physics body has enabled interaction with other body's layer mask.

◆ IsActive()

proto external bool Physics.IsActive ( )

Returns whether the physics body is being simulated (awake).

◆ IsDynamic()

proto external bool Physics.IsDynamic ( )

Returns whether the physics body is dynamic (a rigid body).

◆ IsKinematic()

proto external bool Physics.IsKinematic ( )

Returns whether the physics body is kinematic (animated)

◆ SetActive()

proto external void Physics.SetActive ( ActiveState act)

Changes activation state of the physics body.

◆ SetAngularVelocity()

proto external void Physics.SetAngularVelocity ( vector velocity)

Sets angular velocity of the physics body.

◆ SetDamping()

proto external void Physics.SetDamping ( float linearDamping,
float angularDamping )

Changes damping parameters of the physics body.

◆ SetGeomInteractionLayer()

proto external void Physics.SetGeomInteractionLayer ( int index,
int mask )

Sets interaction layer mask of the geometry element.

◆ SetInertiaTensorV()

proto external void Physics.SetInertiaTensorV ( vector v)

Changes inertia tensor of the physics body.

Parameters
vDiagonal elements of the inertia tensor (a rigid body is aligned with the principle axes of inertia)

◆ SetInteractionLayer()

proto external void Physics.SetInteractionLayer ( int mask)

Sets interaction layer mask of the physics body.

Parameters
maskBit mask of layers

◆ SetLinearFactor()

proto external void Physics.SetLinearFactor ( vector linearFactor)

Sets scale factor for all impulses/velocities/forces. Default is <1,1,1>. Zero any axis if you want to do 2D physics.

◆ SetMass()

proto external void Physics.SetMass ( float mass)

Changes mass of the physics body.

◆ SetResponseIndex()

proto external void Physics.SetResponseIndex ( int responseIndex)

Changes index to response matrix, see "project settings/physics/interactions/response matrix".

Usually this index is set by physics component property, but can be overriden at runtime.

◆ SetSleepingTreshold()

proto external void Physics.SetSleepingTreshold ( float linearTreshold,
float angularTreshold )

Changes thresholds used to determine whether the physics body can stop simulation.

◆ SetTargetMatrix()

proto external void Physics.SetTargetMatrix ( vector matrix[4],
float timeslice )

Sets target transformation.

If timeslice == dt (simulation step delta time), it will happen in next step, otherwise in time = timeslice.

◆ SetVelocity()

proto external void Physics.SetVelocity ( vector velocity)

Sets linear velocity of the physics body.

◆ UpdateGeometries()

proto external bool Physics.UpdateGeometries ( int interactionLayerAnd = 0xffffffff,
int interactionLayerOr = 0 )

Returns world space transformation of a geometry element.

Member Data Documentation

◆ KMH2MS

const float Physics.KMH2MS = 1 / 3.6
static

◆ MS2KMH

const float Physics.MS2KMH = 3.6
static

◆ STANDARD_GRAVITY

const float Physics.STANDARD_GRAVITY = 9.81
static

◆ VGravity

const vector Physics.VGravity = "0 -9.81 0"
static

The documentation for this interface was generated from the following file: