PhysicsBodyclass
Represents a physics object. An entity can have multiple physics objects. See PhysicsGroup. A physics objects consists of one or more PhysicsShapes.
Constructors1
Showing 1 constructors
public PhysicsBody(Sandbox.PhysicsWorld world)
Creates a new physics body in the given world.
| Parameter | Type | Description |
|---|---|---|
| world | PhysicsWorld | — |
No results match this filter.
Methods48
Showing 48 methods
public Sandbox.PhysicsShape AddCapsuleShape(Vector3 center, Vector3 center2, float radius, bool rebuildMass = True)
Add a capsule shape to this body.
| Parameter | Type | Description |
|---|---|---|
| center | Vector3 | — |
| center2 | Vector3 | — |
| radius | float | — |
| rebuildMass = True | bool | — |
public Sandbox.PhysicsShape AddCloneShape(Sandbox.PhysicsShape shape)
Obsolete: This API member is obsolete.
| Parameter | Type | Description |
|---|---|---|
| shape | PhysicsShape | — |
public Sandbox.PhysicsShape AddCylinderShape(Vector3 position, Rotation rotation, float height, float radius, int slices = 16)
Add a cylinder shape to this body.
| Parameter | Type | Description |
|---|---|---|
| position | Vector3 | — |
| rotation | Rotation | — |
| height | float | — |
| radius | float | — |
| slices = 16 | int | — |
public Sandbox.PhysicsShape AddHeightFieldShape(ushort[] heights, byte[] materials, int sizeX, int sizeY, float sizeScale, float heightScale)
Adds a heightfield shape to this physics body.
| Parameter | Type | Description |
|---|---|---|
| heights | ushort[] | — |
| materials | byte[] | — |
| sizeX | int | — |
| sizeY | int | — |
| sizeScale | float | — |
| heightScale | float | — |
public Sandbox.PhysicsShape AddPlaneShape(Vector3 center, Rotation rotation, Vector2 size, bool rebuildMass = True)
Add a plane shape to this body.
| Parameter | Type | Description |
|---|---|---|
| center | Vector3 | — |
| rotation | Rotation | — |
| size | Vector2 | — |
| rebuildMass = True | bool | — |
public void ApplyAngularImpulse(Vector3 impulse)
Applies instant angular impulse to this body.
| Parameter | Type | Description |
|---|---|---|
| impulse | Vector3 | — |
void—public void ApplyForce(Vector3 force)
Applies force to this body at the center of mass.
| Parameter | Type | Description |
|---|---|---|
| force | Vector3 | — |
void—public void ApplyForceAt(Vector3 position, Vector3 force)
Applies force to this body at given position.
| Parameter | Type | Description |
|---|---|---|
| position | Vector3 | — |
| force | Vector3 | — |
void—public void ApplyImpulse(Vector3 impulse)
Applies instant linear impulse to this body at its center of mass.
| Parameter | Type | Description |
|---|---|---|
| impulse | Vector3 | — |
void—public void ApplyImpulseAt(Vector3 position, Vector3 velocity)
Applies instant linear impulse to this body at given position.
| Parameter | Type | Description |
|---|---|---|
| position | Vector3 | — |
| velocity | Vector3 | — |
void—public void ApplyTorque(Vector3 force)
Applies angular velocity to this body.
| Parameter | Type | Description |
|---|---|---|
| force | Vector3 | — |
void—public void ClearForces()
Clear accumulated linear forces during this physics frame that were not yet applied.
void—public void ClearShapes()
Remove all physics shapes, but not the physics body itself.
void—public void ClearTorque()
Clear accumulated torque during this physics frame that was not yet applied.
void—public static Sandbox.PhysicsBody Create(Sandbox.PhysicsWorld world)
Creates a new 3D physics body in the given world.
Obsolete: Use world.CreateBody() instead
| Parameter | Type | Description |
|---|---|---|
| world | PhysicsWorld | — |
public Vector3 FindClosestPoint(Vector3 vec)
Returns the closest point to the given one between all shapes of this body.
| Parameter | Type | Description |
|---|---|---|
| vec | Vector3 | — |
public Sandbox.GameObject GetGameObject()
Obsolete: Use GameObject property
public Transform GetLerpedTransform(double time)
Get the lerped transform between physics steps.
| Parameter | Type | Description |
|---|---|---|
| time | double | — |
public Vector3 GetVelocityAtPoint(Vector3 point)
Returns the world space velocity of a point of the object.
| Parameter | Type | Description |
|---|---|---|
| point | Vector3 | — |
public Sandbox.Physics.PhysicsPoint LocalPoint(Vector3 p)
Convenience function that returns a `Sandbox.Physics.PhysicsPoint` from a position relative to this body.
| Parameter | Type | Description |
|---|---|---|
| p | Vector3 | — |
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, sweeping the shadow if `Sandbox.PhysicsBody.UseController` is enabled.
| Parameter | Type | Description |
|---|---|---|
| tx | Transform | — |
| delta | float | — |
void—public void RebuildMass()
Rebuilds mass from all shapes of this body based on their volume and physics properties.
void—public void Remove()
Completely removes this physics body.
void—public void ResetInertiaTensor()
Resets the inertia tensor to its calculated values.
void—public void SetComponentSource(Sandbox.Component c)
Obsolete: Use Component property
| Parameter | Type | Description |
|---|---|---|
| c | Component | — |
void—public void SetInertiaTensor(Vector3 inertia, Rotation rotation)
Sets the inertia tensor using the given moments and rotation.
| Parameter | Type | Description |
|---|---|---|
| inertia | Vector3 | — |
| rotation | Rotation | — |
void—public void SmoothRotate(Rotation rotation, float smoothTime, float timeDelta)
Rotate the body to this orientation in a way that cooperates with the physics system.
| Parameter | Type | Description |
|---|---|---|
| rotation | Rotation | — |
| smoothTime | float | — |
| timeDelta | float | — |
void—public Sandbox.Physics.PhysicsPoint WorldPoint(Vector3 p)
Convenience function that returns a `Sandbox.Physics.PhysicsPoint` for this body from a world space position.
| Parameter | Type | Description |
|---|---|---|
| p | Vector3 | — |
No results match this filter.
Properties51
Showing 51 properties
public float Sandbox.PhysicsBody.AngularDamping { get; set; }
Generic angular damping, i.e. how much the physics body will slow down on its own.
float—public float Sandbox.PhysicsBody.AngularDrag { get; set; }
Obsolete: This API member is obsolete.
float—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.
bool—public Sandbox.PhysicsBodyType Sandbox.PhysicsBody.BodyType { get; set; }
Movement type of physics body, either Static, Keyframed, Dynamic
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.
float—public bool Sandbox.PhysicsBody.DragEnabled { get; set; }
Obsolete: This API member is obsolete.
bool—public bool Sandbox.PhysicsBody.EnableCollisionSounds { get; set; }
Whether to play collision sounds
bool—public bool Sandbox.PhysicsBody.Enabled { get; set; }
Whether this body is enabled or not.
bool—public bool Sandbox.PhysicsBody.EnableSolidCollisions { get; set; }
Sets `Sandbox.PhysicsShape.EnableSolidCollisions` on all shapes of this body.
bool—public bool Sandbox.PhysicsBody.EnableTouch { get; set; }
Enables Touch callbacks on all PhysicsShapes of this body.
bool—public bool Sandbox.PhysicsBody.EnableTouchPersists { get; set; }
Sets `Sandbox.PhysicsShape.EnableTouchPersists` on all shapes of this body.
bool—public bool Sandbox.PhysicsBody.EnhancedCcd { get; set; }
Enable enhanced continuous collision detection (CCD) for this body.
bool—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.
bool—public float Sandbox.PhysicsBody.GravityScale { get; set; }
Scale the gravity relative to `Sandbox.PhysicsWorld.Gravity`. 2 is double the gravity, etc.
float—public int Sandbox.PhysicsBody.GroupIndex { get; set; }
Return the index of this body in its PhysicsGroup
int—public string Sandbox.PhysicsBody.GroupName { get; set; }
What is this body called in the group?
string—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 virtual sealed bool Sandbox.PhysicsBody.IsValid { get; set; }
bool—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.
float—public float Sandbox.PhysicsBody.LinearDrag { get; set; }
Obsolete: This API member is obsolete.
float—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; }
Locks individual axes of motion for this body.
public float Sandbox.PhysicsBody.Mass { get; set; }
Mass of this physics body.
float—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.
bool—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.
bool—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: This API member is obsolete.
float—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.
int—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; }
You can use this to wake the body up, or prematurely send it to sleep.
bool—public float Sandbox.PhysicsBody.SleepThreshold { get; set; }
The speed threshold below which this body will be put to sleep. Units per second.
float—public bool Sandbox.PhysicsBody.SpeculativeContactEnabled { get; set; }
Obsolete: No longer exists
bool—public Sandbox.Surface Sandbox.PhysicsBody.Surface { get; set; }
public string Sandbox.PhysicsBody.SurfaceMaterial { get; set; }
Sets `Sandbox.PhysicsShape.SurfaceMaterial` on all child PhysicsShapes.
string—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.
bool—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.