PhysicsBody
Sandbox.Engine
Derives from object
Implements IHandle

Summary

Represents a physics object. An entity can have multiple physics objects. See PhysicsGroup. A physics objects consists of one or more PhysicsShapes.

Constructors

Properties

float AngularDamping { get; set; }

Generic angular damping, i.e. how much the physics body will slow down on its own.

float AngularDrag { get; set; }

Amount of air drag to be applied to angular movement/rotation. Default is 1. This should take into account object's rotation and surface area in direction of rotation, unlike PhysicsBody.AngularDamping. See PhysicsWorld.AirDensity and PhysicsBody.DragEnabled.

Vector3 AngularVelocity { get; set; }

Angular velocity of this body in world space.

bool AutoSleep { set; }

Whether this body is allowed to automatically go into "sleep" after a certain amount of time of inactivity. PhysicsBody.Sleeping for more info on the sleep mechanic.

PhysicsBodyType BodyType { get; set; }

Movement type of physics body, either Static, Keyframed, Dynamic Note: If this body is networked and dynamic, it will return Keyframed on the client

float Density { get; }

Returns average of densities for all physics shapes of this body. This is based on PhysicsShape.SurfaceMaterial of each shape.

bool DragEnabled { get; set; }

Whether air drag forces are enabled for this body. See PhysicsWorld.AirDensity, PhysicsBody.AngularDrag and PhysicsBody.LinearDrag.

bool Enabled { get; set; }

Whether this body is enabled or not. Disables collisions, physics simulation, touch events, trace queries, etc.

bool EnableSolidCollisions { get; set; }

Sets PhysicsShape.EnableSolidCollisions on all shapes of this body.

Returns true if ANY of the physics shapes have solid collisions enabled.

bool EnableTouch { get; set; }

Enables Touch callbacks on all PhysicsShapes of this body. See PhysicsShape.EnableTouchEvent.

Returns true if ANY of the physics shapes have touch events enabled.

bool EnableTouchPersists { get; set; }

Sets PhysicsShape.EnableTouchPersists on all shapes of this body.

Returns true if ANY of the physics shapes have persistent touch events enabled.

bool EnableTraceAndQueries { get; set; }

Sets PhysicsShape.EnableTraceAndQueries on all shapes of this body.

Returns true if ANY of the physics shapes have traces and queries enabled.

bool GravityEnabled { get; set; }

Whether gravity is enabled for this body or not.

float GravityScale { get; set; }

Scale the gravity relative to PhysicsWorld.Gravity. 2 is double the gravity, etc.

int GroupIndex { get; }

Return the index of this body in its PhysicsGroup

string GroupName { get; }

What is this body called in the group?

Time since last water splash effect. Used internally.

float LinearDamping { get; set; }

Generic linear damping, i.e. how much the physics body will slow down on its own.

float LinearDrag { get; set; }

Amount of air drag to be applied to linear movement (i.e. not rotational movement). Default is 1. This should take into account object's rotation and surface area in direction of movement, unlike PhysicsBody.LinearDamping. See PhysicsWorld.AirDensity and PhysicsBody.DragEnabled.

Vector3 LocalMassCenter { get; set; }

Center of mass for this physics body relative to its origin.

float Mass { get; set; }

Mass of this physics body.

Vector3 MassCenter { get; }

Center of mass for this physics body in world space coordinates.

bool MotionEnabled { get; set; }

Controls physics simulation on this body.

PhysicsBody Parent { get; set; }

The physics body we are attached to, if any

The physics group we belong to.

Vector3 Position { get; set; }

Position of this body in world coordinates.

Rotation Rotation { get; set; }

Rotation of the physics body in world space.

float Scale { get; }

Returns the scale of this object. (Most of the time inherited from owning entity's scale)

A convenience property, returns Parent, or if there is no parent, returns itself.

IEnumerable<PhysicsShape> Shapes { get; }

All shapes that belong to this body.

bool Sleeping { get; set; }

Physics bodies automatically go to sleep after a certain amount of time of inactivity to save on performance. You can use this to wake the body up, or prematurely send it to sleep.

bool SpeculativeContactEnabled { get; set; }

If enabled, this physics body will move slightly ahead each frame based on its velocities.

string SurfaceMaterial { get; set; }

Returns the most commonly occurring surface name between all PhysicsShapes of this PhysicsBody.

Sets PhysicsShape.SurfaceMaterial on all child PhysicsShapes.

Transform Transform { get; set; }

Transform of this physics body.

bool UseController { get; set; }

If true we'll create a controller for this physics body. This is useful for keyframed physics objects that need to push things. The controller will sweep as the entity moves, rather than teleporting the object.. which works better when pushing dynamic objects etc.

Vector3 Velocity { get; set; }

Linear velocity of this body in world space.

float WaterLevel { get; set; }

How submerged this body is, in range of 0 (not at all) to 1 (fully underwater).

PhysicsWorld World { get; }

The physics world this body belongs to.

Methods

PhysicsShape AddBoxShape( Vector3 position, Rotation rotation, Vector3 extent, bool rebuildMass = true, )

Add a box shape to this body.

PhysicsShape AddCapsuleShape( Vector3 center, Vector3 center2, float radius, bool rebuildMass = true, )

Add a capsule shape to this body.

Clones given shape and adds it to this body.

PhysicsShape AddHullShape( Vector3 position, Rotation rotation, List<Vector3> points, bool rebuildMass = true, )

Add a convex hull shape to this body.

PhysicsShape AddHullShape( Vector3 position, Rotation rotation, Span<Vector3> points, bool rebuildMass = true, )

Add a convex hull shape to this body.

PhysicsShape AddMeshShape( List<Vector3> vertices, List<int> indices, )

Adds a mesh type shape to this physics body. Mesh shapes cannot be physically simulated!

PhysicsShape AddMeshShape( Span<Vector3> vertices, Span<int> indices, )

Adds a mesh type shape to this physics body. Mesh shapes cannot be physically simulated!

PhysicsShape AddSphereShape( Vector3 center, float radius, bool rebuildMass = true, )

Add a sphere shape to this body.

void ApplyAngularImpulse( Vector3 impulse, )

Applies instant angular impulse (i.e. a bullet impact) to this body. For continuous force (i.e. a moving car), use PhysicsBody.ApplyTorque

void ApplyForce( Vector3 force, )

Applies force to this body at the center of mass. This force will only be applied on the next physics frame and is scaled with physics timestep.

void ApplyForceAt( Vector3 position, Vector3 force, )

Applies force to this body at given position. This is akin to a bullet impact off center, and is capable of applying angular forces. This force will only be applied on the next physics frame and is scaled with physics timestep.

void ApplyImpulse( Vector3 impulse, )

Applies instant linear impulse (i.e. a bullet impact) to this body at its center of mass. For continuous force (i.e. a moving car), use PhysicsBody.ApplyForce

void ApplyImpulseAt( Vector3 position, Vector3 velocity, )

Applies instant linear impulse (i.e. a bullet impact) to this body at given position. For continuous force (i.e. a moving car), use PhysicsBody.ApplyForceAt

void ApplyTorque( Vector3 force, )

Applies angular velocity to this body. This force will only be applied on the next physics frame and is scaled with physics timestep.

void ClearForces( )

Clear accumulated linear forces (PhysicsBody.ApplyForce and PhysicsBody.ApplyForceAt) during this physics frame that were not yet applied to the physics body.

void ClearShapes( )

Remove all physics shapes, but not the physics body itself.

void ClearTorque( )

Clear accumulated torque (angular force, PhysicsBody.ApplyTorque) during this physics frame that were not yet applied to the physics body.

Returns the closest point to the given one between all convex shapes of this body.

Returns Axis-Aligned Bounding Box (AABB) of this physics body.

Returns the world space velocity of a point of the object. This is useful for objects rotating around their own axis/origin.

Convenience function that returns a Sandbox.PhysicsPoint from a position relative to this body.

Returns a Sandbox.PhysicsPoint at the center of mass of this body.

void RebuildMass( )

Meant to be only used on dynamic bodies, rebuilds mass from all shapes of this body based on their volume and physics properties, for cases where they may have changed.

void Remove( )

Completely removes this physics body.

void SetMinSolverIterations( int minVelocityIterations, int minPositionIterations, )

Overrides VelocityIterations and PositionIterations of this body's Sandbox.PhysicsWorld at simulation time, if they are lower than given amounts.

Convenience function that returns a Sandbox.PhysicsPoint for this body from a world space position.

Extensions

T GetEntity<T,>( )

Returns the entity this physics body belongs to.

Returns the entity this physics body belongs to.