class PhysicsBody

in global :: Sandbox

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


public Vector3 Position { get; set; }

Position of this body in world coordinates.

public PhysicsWorld World { get; }

The physics world this body belongs to.

public Rotation Rotation { get; set; }

Rotation of the physics body in world space.

public Vector3 Velocity { get; set; }

Linear velocity of this body in world space.

public Vector3 AngularVelocity { get; set; }

Angular velocity of this body in world space.

public Vector3 MassCenter { get; }

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

public Vector3 LocalMassCenter { get; set; }

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

public bool OverrideMassCenter { get; set; }

Is this physics body mass calculated or set directly.

public float Mass { get; set; }

Mass of this physics body.

public bool GravityEnabled { get; set; }

Whether gravity is enabled for this body or not.

public bool EnableCollisionSounds { get; set; }

Whether to play collision sounds

public float GravityScale { get; set; }

Scale the gravity relative to . 2 is double the gravity, etc.

public bool 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 bool 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 EnableTouchPersists { get; set; }

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

public bool EnableSolidCollisions { get; set; }

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

public PhysicsBodyType 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 bool AutoSleep { set; }

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

public Transform Transform { get; set; }

Transform of this physics 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 int ShapeCount { get; }

How many shapes belong to this body.

public IEnumerable<PhysicsShape> Shapes { get; }

All shapes that belong to this body.

public PhysicsShape AddSphereShape( Vector3 center, float radius, bool rebuildMass = True )

Add a sphere shape to this body.

  • center Center of the sphere, relative to of this body.
  • radius Radius of the sphere.
  • rebuildMass Whether the mass should be recalculated after adding the shape.
  • Returns The newly created shape, if any.

public PhysicsShape AddSphereShape( ref Sphere sphere, bool rebuildMass = True )

Add a sphere shape to this body.

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

Add a capsule shape to this body.

  • center Point A of the capsule, relative to of this body.
  • center2 Point B of the capsule, relative to of this body.
  • radius Radius of the capsule end caps.
  • rebuildMass Whether the mass should be recalculated after adding the shape.
  • Returns The newly created shape, or null on failure.

public PhysicsShape AddBoxShape( Vector3 position, Rotation rotation, Vector3 extent, bool rebuildMass = True )

Add a box shape to this body.

  • position Center of the box, relative to of this body.
  • rotation Rotation of the box, relative to of this body.
  • extent The extents of the box. The box will extend from its center by this much in both negative and positive directions of each axis.
  • rebuildMass Whether the mass should be recalculated after adding the shape.
  • Returns The newly created shape, or null on failure.

public PhysicsShape AddBoxShape( BBox box, Rotation rotation, bool rebuildMass = True )

Add a box shape to this body.

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

Add a cylinder shape to this body.

public PhysicsShape AddConeShape( Vector3 position, Rotation rotation, float height, float radius1, float radius2 = 0, int slices = 16 )

Add a cone shape to this body.

public PhysicsShape AddCloneShape( PhysicsShape shape )

Clones given shape and adds it to this body.

  • shape The shape to clone.
  • Returns The cloned shape.

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

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

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

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

  • point The point to test, in world coordinates.
  • Returns Velocity at the given point.

public bool Enabled { get; set; }

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

public bool MotionEnabled { get; set; }

Controls physics simulation on this body.

public bool 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 SpeculativeContactEnabled { get; set; }

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

public PhysicsBody Parent { get; set; }

The physics body we are attached to, if any

public PhysicsBody SelfOrParent { get; }

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

public PhysicsGroup PhysicsGroup { get; }

The physics group we belong to.

public Vector3 FindClosestPoint( Vector3 vec )

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

  • vec Input position.
  • Returns The closest possible position on the surface of the physics body to the given position.

public float LinearDamping { get; set; }

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

public float AngularDamping { get; set; }

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

public Vector3 Inertia { get; }

The diagonal elements of the local inertia tensor matrix.

public Rotation InertiaRotation { get; }

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

public void SetInertiaTensor( Vector3 inertia, Rotation rotation )

Sets the inertia tensor using the given moments and rotation.

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

public float Density { get; }

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

public RealTimeSince LastWaterEffect { get; set; }

Time since last water splash effect. Used internally.

public string SurfaceMaterial { get; set; }

Sets on all child PhysicsShapes.

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

public PhysicsPoint LocalPoint( Vector3 p )

Convenience function that returns a from a position relative to this body.

public PhysicsPoint WorldPoint( Vector3 p )

Convenience function that returns a for this body from a world space position.

public string GroupName { get; }

What is this body called in the group?

public int GroupIndex { get; }

Return the index of this body in its PhysicsGroup

public bool CheckOverlap( PhysicsBody body )

Checks if another body overlaps us, ignoring all collision rules

public bool CheckOverlap( PhysicsBody body, Transform transform )

Checks if another body overlaps us at a given transform, ignoring all collision rules

public PhysicsShape AddShape( PhysicsGroupDescription.BodyPart.HullPart part, Transform transform, bool rebuildMass = True )

Add a shape from a physics hull

public PhysicsShape AddShape( PhysicsGroupDescription.BodyPart.MeshPart part, Transform transform, bool convertToHull, bool rebuildMass = True )

Add a shape from a mesh hull

public Transform GetLerpedTransform( float 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 void SmoothMove( ref Vector3 position, float timeToArrive, float timeDelta )

Move body to this position in a way that cooperates with the physics system. This is quite good for things like grabbing and moving objects.

public void SmoothMove( ref Transform transform, float smoothTime, float timeDelta )

Move body to this position in a way that cooperates with the physics system. This is quite good for things like grabbing and moving objects.

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

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

public bool Equals( object obj )

😔 No documentation found.

public PhysicsLock Locking { get; set; }

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public Action<PhysicsIntersectionEnd> OnIntersectionEnd { get; set; }

😔 No documentation found.

public Action<PhysicsIntersection> OnIntersectionUpdate { get; set; }

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public Action<PhysicsIntersection> OnIntersectionStart { get; set; }

😔 No documentation found.

public PhysicsBody( PhysicsWorld world )

😔 No documentation found.

public void ClearForces( )

😔 No documentation found.

public float Scale { get; }

😔 No documentation found.

public PhysicsShape AddHullShape( Vector3 position, Rotation rotation, List<Vector3> points, bool rebuildMass = True )

😔 No documentation found.

public PhysicsShape AddHullShape( Vector3 position, Rotation rotation, Span<Vector3> points, bool rebuildMass = True )

😔 No documentation found.

public PhysicsShape AddMeshShape( List<Vector3> vertices, List<int> indices )

😔 No documentation found.

public PhysicsShape AddMeshShape( Span<Vector3> vertices, Span<int> indices )

😔 No documentation found.

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

😔 No documentation found.

public void ClearShapes( )

😔 No documentation found.

public PhysicsPoint MassCenterPoint( )

😔 No documentation found.

public void RebuildMass( )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public void ClearTorque( )

😔 No documentation found.

public float LinearDrag { get; set; }

😔 No documentation found.

public float AngularDrag { get; set; }

😔 No documentation found.

public bool DragEnabled { get; set; }

😔 No documentation found.

public void ResetInertiaTensor( )

😔 No documentation found.

public BBox GetBounds( )

😔 No documentation found.

public void Remove( )

😔 No documentation found.

public Surface Surface { get; set; }

😔 No documentation found.