PhysicsBodyclass

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

objectPhysicsBody
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.PhysicsBody

Constructors1

Showing 1 constructors

Methods44

Showing 44 methods

public Sandbox.PhysicsShape AddCapsuleShape(Vector3 center, Vector3 center2, float radius, bool rebuildMass = True)PUBLIC

Add a capsule shape to this body.

ParameterTypeDescription
centerVector3Point A of the capsule, relative to `Sandbox.PhysicsBody.Position` of this body.
center2Vector3Point B of the capsule, relative to `Sandbox.PhysicsBody.Position` of this body.
radiusfloatRadius of the capsule end caps.
rebuildMass = TrueboolWhether the mass should be recalculated after adding the shape.
Returns:PhysicsShapeThe newly created shape, or null on failure.

public Sandbox.PhysicsShape AddCylinderShape(Vector3 position, Rotation rotation, float height, float radius, int slices = 16)PUBLIC

Add a cylinder shape to this body.

ParameterTypeDescription
positionVector3
rotationRotation
heightfloat
radiusfloat
slices = 16int
Returns:PhysicsShape

public Sandbox.PhysicsShape AddHeightFieldShape(ushort[] heights, byte[] materials, int sizeX, int sizeY, float sizeScale, float heightScale)PUBLIC

ParameterTypeDescription
heightsushort[]
materialsbyte[]
sizeXint
sizeYint
sizeScalefloat
heightScalefloat
Returns:PhysicsShape

public void ApplyAngularImpulse(Vector3 impulse)PUBLIC

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

ParameterTypeDescription
impulseVector3
Returns:void

public void ApplyForce(Vector3 force)PUBLIC

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.

ParameterTypeDescription
forceVector3
Returns:void

public void ApplyForceAt(Vector3 position, Vector3 force)PUBLIC

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

ParameterTypeDescription
positionVector3
forceVector3
Returns:void

public void ApplyImpulse(Vector3 impulse)PUBLIC

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 `Sandbox.PhysicsBody.ApplyForce(Vector3)`

ParameterTypeDescription
impulseVector3
Returns:void

public void ApplyImpulseAt(Vector3 position, Vector3 velocity)PUBLIC

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

ParameterTypeDescription
positionVector3
velocityVector3
Returns:void

public void ApplyTorque(Vector3 force)PUBLIC

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

ParameterTypeDescription
forceVector3
Returns:void

public void ClearForces()PUBLIC

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

Returns:void

public void ClearShapes()PUBLIC

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

Returns:void

public void ClearTorque()PUBLIC

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

Returns:void

public Vector3 FindClosestPoint(Vector3 vec)PUBLIC

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

ParameterTypeDescription
vecVector3Input position.
Returns:Vector3The closest possible position on the surface of the physics body to the given position.

public BBox GetBounds()PUBLIC

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

Returns:BBox

public Sandbox.GameObject GetGameObject()PUBLICOBSOLETE

Obsolete: Use GameObject property

Returns:GameObject

public Transform GetLerpedTransform(double time)PUBLIC

When the physics world is run at a fixed timestep, getting the positions of bodies will not be smooth. You can use this function to get the lerped position between steps, to make things super awesome.

ParameterTypeDescription
timedouble
Returns:Transform

public Vector3 GetVelocityAtPoint(Vector3 point)PUBLIC

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

ParameterTypeDescription
pointVector3The point to test, in world coordinates.
Returns:Vector3Velocity at the given point.

public Sandbox.Physics.PhysicsPoint LocalPoint(Vector3 p)PUBLIC

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

ParameterTypeDescription
pVector3
Returns:PhysicsPoint

public Sandbox.Physics.PhysicsPoint MassCenterPoint()PUBLIC

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

Returns:PhysicsPoint

public void Move(Transform tx, float delta)PUBLIC

Move to a new position. Unlike Transform, if you have `UseController` enabled, this will sweep the shadow to the new position, rather than teleporting there.

ParameterTypeDescription
txTransform
deltafloat
Returns:void

public void RebuildMass()PUBLIC

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.

Returns:void

public void Remove()PUBLIC

Completely removes this physics body.

Returns:void

public void ResetInertiaTensor()PUBLIC

Resets the inertia tensor to its calculated values.

Returns:void

public void SetComponentSource(Sandbox.Component c)PUBLICOBSOLETE

Obsolete: Use Component property

ParameterTypeDescription
cComponent
Returns:void

public void SetInertiaTensor(Vector3 inertia, Rotation rotation)PUBLIC

Sets the inertia tensor using the given moments and rotation.

ParameterTypeDescription
inertiaVector3Principal moments (Ixx, Iyy, Izz).
rotationRotationRotation of the principal axes.
Returns:void

public void SmoothRotate(Rotation rotation, float smoothTime, float timeDelta)PUBLIC

Rotate the body to this position in a way that cooperates with the physics system.

ParameterTypeDescription
rotationRotation
smoothTimefloat
timeDeltafloat
Returns:void

public Sandbox.Physics.PhysicsPoint WorldPoint(Vector3 p)PUBLIC

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

ParameterTypeDescription
pVector3
Returns:PhysicsPoint

Properties50

Showing 50 properties

public float Sandbox.PhysicsBody.AngularDamping { get; set; }PUBLICGETSET

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

Returns:float

public float Sandbox.PhysicsBody.AngularDrag { get; set; }PUBLICGETSETOBSOLETE

Obsolete: This API member is obsolete.

Returns:float

public Vector3 Sandbox.PhysicsBody.AngularVelocity { get; set; }PUBLICGETSET

Angular velocity of this body in world space.

Returns:Vector3

public bool Sandbox.PhysicsBody.AutoSleep { get; set; }PUBLICGETSET

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

Returns:bool

public Sandbox.PhysicsBodyType Sandbox.PhysicsBody.BodyType { get; set; }PUBLICGETSET

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

Returns:PhysicsBodyType

public float Sandbox.PhysicsBody.Density { get; set; }PUBLICGETSET

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

Returns:float

public bool Sandbox.PhysicsBody.DragEnabled { get; set; }PUBLICGETSETOBSOLETE

Obsolete: This API member is obsolete.

Returns:bool

public bool Sandbox.PhysicsBody.EnableCollisionSounds { get; set; }PUBLICGETSET

Whether to play collision sounds

Returns:bool

public bool Sandbox.PhysicsBody.Enabled { get; set; }PUBLICGETSET

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

Returns:bool

public bool Sandbox.PhysicsBody.EnableSolidCollisions { get; set; }PUBLICGETSET

Sets `Sandbox.PhysicsShape.EnableSolidCollisions` on all shapes of this body. Returns true if ANY of the physics shapes have solid collisions enabled.

Returns:bool

public bool Sandbox.PhysicsBody.EnableTouch { get; set; }PUBLICGETSET

Enables Touch callbacks on all PhysicsShapes of this body. Returns true if ANY of the physics shapes have touch events enabled.

Returns:bool

public bool Sandbox.PhysicsBody.EnableTouchPersists { get; set; }PUBLICGETSET

Sets `Sandbox.PhysicsShape.EnableTouchPersists` on all shapes of this body. Returns true if ANY of the physics shapes have persistent touch events enabled.

Returns:bool

public bool Sandbox.PhysicsBody.EnhancedCcd { get; set; }PUBLICGETSET

Enable enhanced continuous collision detection (CCD) for this body. When enabled, the body performs CCD against dynamic bodies (but not against other bodies with enhanced CCD enabled). This is useful for fast-moving objects like bullets or rockets that need reliable collision detection.

Returns:bool

public bool Sandbox.PhysicsBody.GravityEnabled { get; set; }PUBLICGETSET

Whether gravity is enabled for this body or not.

Returns:bool

public float Sandbox.PhysicsBody.GravityScale { get; set; }PUBLICGETSET

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

Returns:float

public int Sandbox.PhysicsBody.GroupIndex { get; set; }PUBLICGETSET

Return the index of this body in its PhysicsGroup

Returns:int

public string Sandbox.PhysicsBody.GroupName { get; set; }PUBLICGETSET

What is this body called in the group?

Returns:string

public Vector3 Sandbox.PhysicsBody.Inertia { get; set; }PUBLICGETSET

The diagonal elements of the local inertia tensor matrix.

Returns:Vector3

public Rotation Sandbox.PhysicsBody.InertiaRotation { get; set; }PUBLICGETSET

The orientation of the principal axes of local inertia tensor matrix.

Returns:Rotation

public float Sandbox.PhysicsBody.LinearDamping { get; set; }PUBLICGETSET

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

Returns:float

public float Sandbox.PhysicsBody.LinearDrag { get; set; }PUBLICGETSETOBSOLETE

Obsolete: This API member is obsolete.

Returns:float

public Vector3 Sandbox.PhysicsBody.LocalMassCenter { get; set; }PUBLICGETSET

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

Returns:Vector3

public float Sandbox.PhysicsBody.Mass { get; set; }PUBLICGETSET

Mass of this physics body.

Returns:float

public Vector3 Sandbox.PhysicsBody.MassCenter { get; set; }PUBLICGETSET

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

Returns:Vector3

public bool Sandbox.PhysicsBody.MotionEnabled { get; set; }PUBLICGETSET

Controls physics simulation on this body.

Returns:bool

public bool Sandbox.PhysicsBody.OverrideMassCenter { get; set; }PUBLICGETSET

Is this physics body mass calculated or set directly.

Returns:bool

public float Sandbox.PhysicsBody.Scale { get; set; }PUBLICGETSETOBSOLETE

Obsolete: This API member is obsolete.

Returns:float

public Sandbox.PhysicsBody Sandbox.PhysicsBody.SelfOrParent { get; set; }PUBLICGETSET

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

Returns:PhysicsBody

public int Sandbox.PhysicsBody.ShapeCount { get; set; }PUBLICGETSET

How many shapes belong to this body.

Returns:int

public System.Collections.Generic.IEnumerable`1<Sandbox.PhysicsShape> Sandbox.PhysicsBody.Shapes { get; set; }PUBLICGETSET

All shapes that belong to this body.

Returns:IEnumerable<PhysicsShape>

public bool Sandbox.PhysicsBody.Sleeping { get; set; }PUBLICGETSET

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.

Returns:bool

public float Sandbox.PhysicsBody.SleepThreshold { get; set; }PUBLICGETSET

The speed threshold below which this body will be put to sleep. Units per second. The default is about 2 units/sec. Increase this to make bodies sleep sooner, which is useful for stacking stability.

Returns:float

public bool Sandbox.PhysicsBody.SpeculativeContactEnabled { get; set; }PUBLICGETSETOBSOLETE

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

Obsolete: No longer exists

Returns:bool

public string Sandbox.PhysicsBody.SurfaceMaterial { get; set; }PUBLICGETSET

Sets `Sandbox.PhysicsShape.SurfaceMaterial` on all child PhysicsShapes.

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

public bool Sandbox.PhysicsBody.UseController { get; set; }PUBLICGETSET

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.

Returns:bool

public Vector3 Sandbox.PhysicsBody.Velocity { get; set; }PUBLICGETSET

Linear velocity of this body in world space.

Returns:Vector3

On this page

Constructorspublic PhysicsBody(Sandbox.PhysicsWorld world)Methodspublic Sandbox.PhysicsShape AddBoxShape(BBox box, Rotation rotation, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddBoxShape(Vector3 position, Rotation rotation, Vector3 extent, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddCapsuleShape(Vector3 center, Vector3 center2, System.Single radius, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddCloneShape(Sandbox.PhysicsShape shape)public Sandbox.PhysicsShape AddConeShape(Vector3 position, Rotation rotation, System.Single height, System.Single radius1, System.Single radius2 = 0, System.Int32 slices = 16)public Sandbox.PhysicsShape AddConeShape(Vector3 a, Vector3 b, System.Single radiusA, System.Single radiusB, System.Int32 slices = 16)public Sandbox.PhysicsShape AddCylinderShape(Vector3 position, Rotation rotation, System.Single height, System.Single radius, System.Int32 slices = 16)public Sandbox.PhysicsShape AddHeightFieldShape(System.UInt16[] heights, System.Byte[] materials, System.Int32 sizeX, System.Int32 sizeY, System.Single sizeScale, System.Single heightScale)public Sandbox.PhysicsShape AddHullShape(Vector3 position, Rotation rotation, System.Collections.Generic.List`1<Vector3> points, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddHullShape(Vector3 position, Rotation rotation, System.Span`1<Vector3> points, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddMeshShape(System.Collections.Generic.List`1<Vector3> vertices, System.Collections.Generic.List`1<System.Int32> indices)public Sandbox.PhysicsShape AddMeshShape(System.Span`1<Vector3> vertices, System.Span`1<System.Int32> indices)public Sandbox.PhysicsShape AddShape(Sandbox.PhysicsGroupDescription.BodyPart.HullPart part, Transform transform, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddShape(Sandbox.PhysicsGroupDescription.BodyPart.MeshPart part, Transform transform, System.Boolean convertToHull, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddSphereShape(Sandbox.Sphere sphere, System.Boolean rebuildMass = True)public Sandbox.PhysicsShape AddSphereShape(Vector3 center, System.Single radius, System.Boolean rebuildMass = True)public System.Void ApplyAngularImpulse(Vector3 impulse)public System.Void ApplyForce(Vector3 force)public System.Void ApplyForceAt(Vector3 position, Vector3 force)public System.Void ApplyImpulse(Vector3 impulse)public System.Void ApplyImpulseAt(Vector3 position, Vector3 velocity)public System.Void ApplyTorque(Vector3 force)public System.Boolean CheckOverlap(Sandbox.PhysicsBody body, Transform transform)public System.Boolean CheckOverlap(Sandbox.PhysicsBody body)public System.Void ClearForces()public System.Void ClearShapes()public System.Void ClearTorque()public Vector3 FindClosestPoint(Vector3 vec)public BBox GetBounds()public Sandbox.GameObject GetGameObject()public Transform GetLerpedTransform(System.Double time)public Vector3 GetVelocityAtPoint(Vector3 point)public Sandbox.Physics.PhysicsPoint LocalPoint(Vector3 p)public Sandbox.Physics.PhysicsPoint MassCenterPoint()public System.Void Move(Transform tx, System.Single delta)public System.Void RebuildMass()public System.Void Remove()public System.Void ResetInertiaTensor()public System.Void SetComponentSource(Sandbox.Component c)public System.Void SetInertiaTensor(Vector3 inertia, Rotation rotation)public System.Void SmoothMove(Transform transform, System.Single smoothTime, System.Single timeDelta)public System.Void SmoothMove(Vector3 position, System.Single timeToArrive, System.Single timeDelta)public System.Void SmoothRotate(Rotation rotation, System.Single smoothTime, System.Single timeDelta)public Sandbox.Physics.PhysicsPoint WorldPoint(Vector3 p)Propertiespublic System.Single Sandbox.PhysicsBody.AngularDamping { get; set; }public System.Single Sandbox.PhysicsBody.AngularDrag { get; set; }public Vector3 Sandbox.PhysicsBody.AngularVelocity { get; set; }public System.Boolean Sandbox.PhysicsBody.AutoSleep { get; set; }public Sandbox.PhysicsBodyType Sandbox.PhysicsBody.BodyType { get; set; }public Sandbox.Component Sandbox.PhysicsBody.Component { get; set; }public System.Single Sandbox.PhysicsBody.Density { get; set; }public System.Boolean Sandbox.PhysicsBody.DragEnabled { get; set; }public System.Boolean Sandbox.PhysicsBody.EnableCollisionSounds { get; set; }public System.Boolean Sandbox.PhysicsBody.Enabled { get; set; }public System.Boolean Sandbox.PhysicsBody.EnableSolidCollisions { get; set; }public System.Boolean Sandbox.PhysicsBody.EnableTouch { get; set; }public System.Boolean Sandbox.PhysicsBody.EnableTouchPersists { get; set; }public System.Boolean Sandbox.PhysicsBody.EnhancedCcd { get; set; }public Sandbox.GameObject Sandbox.PhysicsBody.GameObject { get; set; }public System.Boolean Sandbox.PhysicsBody.GravityEnabled { get; set; }public System.Single Sandbox.PhysicsBody.GravityScale { get; set; }public System.Int32 Sandbox.PhysicsBody.GroupIndex { get; set; }public System.String Sandbox.PhysicsBody.GroupName { get; set; }public Vector3 Sandbox.PhysicsBody.Inertia { get; set; }public Rotation Sandbox.PhysicsBody.InertiaRotation { get; set; }public Sandbox.RealTimeSince Sandbox.PhysicsBody.LastWaterEffect { get; set; }public System.Single Sandbox.PhysicsBody.LinearDamping { get; set; }public System.Single Sandbox.PhysicsBody.LinearDrag { get; set; }public Vector3 Sandbox.PhysicsBody.LocalMassCenter { get; set; }public Sandbox.PhysicsLock Sandbox.PhysicsBody.Locking { get; set; }public System.Single Sandbox.PhysicsBody.Mass { get; set; }public Vector3 Sandbox.PhysicsBody.MassCenter { get; set; }public System.Boolean Sandbox.PhysicsBody.MotionEnabled { get; set; }public System.Action`1<Sandbox.PhysicsIntersectionEnd> Sandbox.PhysicsBody.OnIntersectionEnd { get; set; }public System.Action`1<Sandbox.PhysicsIntersection> Sandbox.PhysicsBody.OnIntersectionStart { get; set; }public System.Action`1<Sandbox.PhysicsIntersection> Sandbox.PhysicsBody.OnIntersectionUpdate { get; set; }public System.Boolean Sandbox.PhysicsBody.OverrideMassCenter { get; set; }public Sandbox.PhysicsBody Sandbox.PhysicsBody.Parent { get; set; }public Sandbox.PhysicsGroup Sandbox.PhysicsBody.PhysicsGroup { get; set; }public Vector3 Sandbox.PhysicsBody.Position { get; set; }public Rotation Sandbox.PhysicsBody.Rotation { get; set; }public System.Single Sandbox.PhysicsBody.Scale { get; set; }public Sandbox.PhysicsBody Sandbox.PhysicsBody.SelfOrParent { get; set; }public System.Int32 Sandbox.PhysicsBody.ShapeCount { get; set; }public System.Collections.Generic.IEnumerable`1<Sandbox.PhysicsShape> Sandbox.PhysicsBody.Shapes { get; set; }public System.Boolean Sandbox.PhysicsBody.Sleeping { get; set; }public System.Single Sandbox.PhysicsBody.SleepThreshold { get; set; }public System.Boolean Sandbox.PhysicsBody.SpeculativeContactEnabled { get; set; }public Sandbox.Surface Sandbox.PhysicsBody.Surface { get; set; }public System.String Sandbox.PhysicsBody.SurfaceMaterial { get; set; }public Transform Sandbox.PhysicsBody.Transform { get; set; }public System.Boolean Sandbox.PhysicsBody.UseController { get; set; }public Vector3 Sandbox.PhysicsBody.Velocity { get; set; }public Sandbox.PhysicsWorld Sandbox.PhysicsBody.World { get; set; }Metadata