PhysicsBodyclass

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

object→PhysicsBody
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.PhysicsBody

Constructors1

Showing 1 constructors

Methods48

Showing 48 methods

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

Add a capsule shape to this body.

ParameterTypeDescription
centerVector3—
center2Vector3—
radiusfloat—
rebuildMass = Truebool—
Returns:PhysicsShape—

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

Adds a heightfield shape to this physics body.

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

public void ApplyAngularImpulse(Vector3 impulse)PUBLIC

Applies instant angular impulse to this body.

ParameterTypeDescription
impulseVector3—
Returns:void—

public void ApplyForce(Vector3 force)PUBLIC

Applies force to this body at the center of mass.

ParameterTypeDescription
forceVector3—
Returns:void—

public void ApplyForceAt(Vector3 position, Vector3 force)PUBLIC

Applies force to this body at given position.

ParameterTypeDescription
positionVector3—
forceVector3—
Returns:void—

public void ApplyImpulse(Vector3 impulse)PUBLIC

Applies instant linear impulse to this body at its center of mass.

ParameterTypeDescription
impulseVector3—
Returns:void—

public void ApplyImpulseAt(Vector3 position, Vector3 velocity)PUBLIC

Applies instant linear impulse to this body at given position.

ParameterTypeDescription
positionVector3—
velocityVector3—
Returns:void—

public void ApplyTorque(Vector3 force)PUBLIC

Applies angular velocity to this body.

ParameterTypeDescription
forceVector3—
Returns:void—

public void ClearForces()PUBLIC

Clear accumulated linear forces during this physics frame that were not yet applied.

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 during this physics frame that was not yet applied.

Returns:void—

public static Sandbox.PhysicsBody Create(Sandbox.PhysicsWorld world)PUBLICSTATICOBSOLETE

Creates a new 3D physics body in the given world.

Obsolete: Use world.CreateBody() instead

ParameterTypeDescription
worldPhysicsWorld—
Returns:PhysicsBody—

public Vector3 FindClosestPoint(Vector3 vec)PUBLIC

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

ParameterTypeDescription
vecVector3—
Returns:Vector3—

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

Get the lerped transform between physics steps.

ParameterTypeDescription
timedouble—
Returns:Transform—

public Vector3 GetVelocityAtPoint(Vector3 point)PUBLIC

Returns the world space velocity of a point of the object.

ParameterTypeDescription
pointVector3—
Returns:Vector3—

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, sweeping the shadow if `Sandbox.PhysicsBody.UseController` is enabled.

ParameterTypeDescription
txTransform—
deltafloat—
Returns:void—

public void RebuildMass()PUBLIC

Rebuilds mass from all shapes of this body based on their volume and physics properties.

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
inertiaVector3—
rotationRotation—
Returns:void—

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

Rotate the body to this orientation 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—

Properties51

Showing 51 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.

Returns:bool—

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

Returns average of densities for all physics shapes of this body.

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.

Returns:bool—

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

Sets `Sandbox.PhysicsShape.EnableSolidCollisions` on all shapes of this body.

Returns:bool—

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

Enables Touch callbacks on all PhysicsShapes of this body.

Returns:bool—

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

Sets `Sandbox.PhysicsShape.EnableTouchPersists` on all shapes of this body.

Returns:bool—

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

Enable enhanced continuous collision detection (CCD) for this body.

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 virtual sealed bool Sandbox.PhysicsBody.IsValid { get; set; }PUBLICVIRTUALGETSET

Returns:bool—

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

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.

Returns:float—

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

Obsolete: No longer exists

Returns:bool—

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

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

Returns:string—

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

If true we'll create a controller for this physics body.

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 AddPlaneShape(Vector3 center, Rotation rotation, Vector2 size, System.Boolean rebuildMass = True)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 System.Boolean ComputePenetration(Sandbox.PhysicsBody body, Transform transform, Vector3 direction, System.Single distance)public System.Boolean ComputePenetration(Sandbox.PhysicsBody body, Vector3 direction, System.Single distance)public static Sandbox.PhysicsBody Create(Sandbox.PhysicsWorld world)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 virtual sealed System.Boolean Sandbox.PhysicsBody.IsValid { 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