classPhysicsBody

Constructors

note_add PhysicsBody( world )

Properties

data_object AngularDampingdata_object AngularDragdata_object AngularVelocitydata_object AutoSleepdata_object BodyTypedata_object Densitydata_object DragEnableddata_object Enableddata_object EnableSolidCollisionsdata_object EnableTouchdata_object EnableTouchPersistsdata_object EnableTraceAndQueriesdata_object GravityEnableddata_object GravityScaledata_object GroupIndexdata_object GroupNamedata_object Inertiadata_object InertiaRotationdata_object LastWaterEffectdata_object LinearDampingdata_object LinearDragdata_object LocalMassCenterdata_object Massdata_object MassCenterdata_object MotionEnableddata_object Parentdata_object PhysicsGroupdata_object Positiondata_object Rotationdata_object Scaledata_object SelfOrParentdata_object Shapesdata_object Sleepingdata_object SpeculativeContactEnableddata_object SurfaceMaterialdata_object Transformdata_object UseControllerdata_object Velocitydata_object World

Methods

code AddBoxShape( position, rotation, extent, rebuildMass ) code AddCapsuleShape( center, center2, radius, rebuildMass ) code AddCloneShape( shape ) code AddHullShape( position, rotation, points, rebuildMass ) code AddHullShape( position, rotation, points, rebuildMass ) code AddMeshShape( vertices, indices ) code AddMeshShape( vertices, indices ) code AddSphereShape( center, radius, rebuildMass ) code ApplyAngularImpulse( impulse ) code ApplyForce( force ) code ApplyForceAt( position, force ) code ApplyImpulse( impulse ) code ApplyImpulseAt( position, velocity ) code ApplyTorque( force ) code CheckOverlap( body ) code CheckOverlap( body, transform ) code ClearForces() code ClearShapes() code ClearTorque() code FindClosestPoint( vec ) code GetBounds() code GetVelocityAtPoint( point ) code LocalPoint( p ) code MassCenterPoint() code RebuildMass() code Remove() code SetMinSolverIterations( minVelocityIterations, minPositionIterations ) code WorldPoint( p )

Extensions

code GetEntity<T>() code GetEntity()
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. 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?

Vector3 Inertia { get; }

The diagonal elements of the inertia tensor matrix.

The orientation of the principal axes of inertia tensor matrix.

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

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.

bool CheckOverlap( PhysicsBody body, )

Checks if another body overlaps us, ignoring all collision rules

bool CheckOverlap( PhysicsBody body, Transform transform, )

Checks if another body overlaps us at a given transform, ignoring all collision rules

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 Physics.PhysicsPoint from a position relative to this body.

Returns a Physics.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 Physics.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.