s&box docs

public sealed class Sandbox.PhysicsBody

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

Constructors

Showing 1 constructors

Methods

Showing 44 methods

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

Add a capsule shape to this body.

Parameters

  • center: Point A of the capsule, relative to `Sandbox.PhysicsBody.Position` of this body.
  • center2: Point B of the capsule, relative to `Sandbox.PhysicsBody.Position` of this body.
  • radius: Radius of the capsule end caps.
  • rebuildMass: Whether the mass should be recalculated after adding the shape. Default: True

Returns

The newly created shape, or null on failure.

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

Add a cylinder shape to this body.

Parameters

  • slices: Default: 16

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

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

public 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.

public void ApplyForceAt(Vector3 position, Vector3 force)

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.

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

public 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 `Sandbox.PhysicsBody.ApplyForceAt(Vector3,Vector3)`

public 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.

public void ClearForces()

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.

public void ClearShapes()

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

public void ClearTorque()

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

public Vector3 FindClosestPoint(Vector3 vec)

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

Parameters

  • vec: Input position.

Returns

The closest possible position on the surface of the physics body to the given position.

public BBox GetBounds()

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

public Sandbox.GameObject GetGameObject()Obsolete

Obsolete: Use GameObject property

public Transform GetLerpedTransform(double time)

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.

public Vector3 GetVelocityAtPoint(Vector3 point)

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

Parameters

  • point: The point to test, in world coordinates.

Returns

Velocity at the given point.

public Sandbox.Physics.PhysicsPoint LocalPoint(Vector3 p)

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

public Sandbox.Physics.PhysicsPoint MassCenterPoint()

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

public void Move(Transform tx, float delta)

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.

public 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.

public void Remove()

Completely removes this physics body.

public void ResetInertiaTensor()

Resets the inertia tensor to its calculated values.

public void SetComponentSource(Sandbox.Component c)Obsolete

Obsolete: Use Component property

public void SetInertiaTensor(Vector3 inertia, Rotation rotation)

Sets the inertia tensor using the given moments and rotation.

Parameters

  • inertia: Principal moments (Ixx, Iyy, Izz).
  • rotation: Rotation of the principal axes.

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

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

public Sandbox.Physics.PhysicsPoint WorldPoint(Vector3 p)

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

Properties

Showing 49 properties

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

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

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

Obsolete: This API member is obsolete.

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

Angular velocity of this body in world space.

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

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.

public Sandbox.PhysicsBodyType Sandbox.PhysicsBody.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

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

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

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

Obsolete: This API member is obsolete.

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

Whether to play collision sounds

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

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

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

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

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

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

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

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

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

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.

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

Whether gravity is enabled for this body or not.

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

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

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

Return the index of this body in its PhysicsGroup

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

What is this body called in the group?

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

The diagonal elements of the local inertia tensor matrix.

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

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

public Sandbox.RealTimeSince Sandbox.PhysicsBody.LastWaterEffect { get; set; }

Time since last water splash effect. Used internally.

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

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

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

Obsolete: This API member is obsolete.

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

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

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

Mass of this physics body.

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

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

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

Controls physics simulation on this body.

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

Is this physics body mass calculated or set directly.

public Sandbox.PhysicsBody Sandbox.PhysicsBody.Parent { get; set; }

The physics body we are attached to, if any

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

Obsolete: This API member is obsolete.

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

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

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

How many shapes belong to this body.

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

All shapes that belong to this body.

public bool Sandbox.PhysicsBody.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.

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

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

Obsolete: No longer exists

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

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

Returns

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

public bool Sandbox.PhysicsBody.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.

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

Linear velocity of this body in world space.

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.Engine
Doc IDT:Sandbox.PhysicsBody

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