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
public PhysicsBody(Sandbox.PhysicsWorld world)
No results match this filter.
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 AddCloneShape(Sandbox.PhysicsShape shape)Obsolete
Obsolete: This API member is obsolete.
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.
No results match this filter.
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 Sandbox.Component Sandbox.PhysicsBody.Component { get; set; }
The component that created this body
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 Sandbox.GameObject Sandbox.PhysicsBody.GameObject { get; set; }
The GameObject that created this body
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 Sandbox.PhysicsLock Sandbox.PhysicsBody.Locking { get; set; }
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 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 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 Sandbox.PhysicsGroup Sandbox.PhysicsBody.PhysicsGroup { get; set; }
The physics group we belong to.
public Vector3 Sandbox.PhysicsBody.Position { get; set; }
Position of this body in world coordinates.
public Rotation Sandbox.PhysicsBody.Rotation { get; set; }
Rotation of the physics body in world space.
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 Sandbox.Surface Sandbox.PhysicsBody.Surface { get; set; }
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 Transform Sandbox.PhysicsBody.Transform { get; set; }
Transform of this physics body.
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.
public Sandbox.PhysicsWorld Sandbox.PhysicsBody.World { get; set; }
The physics world this body belongs to.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.PhysicsBody |