Barotrauma Client Doc
Barotrauma.PhysicsBody Class Reference

Public Types

enum class  Shape { Circle , Rectangle , Capsule , HorizontalCapsule }
 

Public Member Functions

float TransformRotation (float rotation)
 
 PhysicsBody (XElement element, float scale=1.0f, bool findNewContacts=true)
 
 PhysicsBody (ColliderParams cParams, bool findNewContacts=true)
 
 PhysicsBody (LimbParams lParams, bool findNewContacts=true)
 
 PhysicsBody (float width, float height, float radius, float density, BodyType bodyType, Category collisionCategory, Category collidesWith, bool findNewContacts=true)
 
 PhysicsBody (Body farseerBody)
 
 PhysicsBody (ColliderParams colliderParams, Vector2 position, bool findNewContacts=true)
 
 PhysicsBody (LimbParams limbParams, Vector2 position, bool findNewContacts=true)
 
 PhysicsBody (XElement element, Vector2 position, float scale=1.0f, float? forceDensity=null, Category collisionCategory=Physics.CollisionItem, Category collidesWith=Physics.CollisionWall|Physics.CollisionLevel|Physics.CollisionPlatform, bool findNewContacts=true)
 
Vector2 GetLocalFront (float? spritesheetRotation=null)
 Returns the farthest point towards the forward of the body. For capsules and circles, the front is at the top. For horizontal capsules, the front is at the right-most point. For rectangles, the front is either at the top or at the right, depending on which one of the two is greater: width or height. The rotation is in radians. More...
 
float GetMaxExtent ()
 
Vector2 GetSize ()
 
void SetSize (Vector2 size)
 
bool IsValidValue (float value, string valueName, float minValue=float.MinValue, float maxValue=float.MaxValue)
 
void ResetDynamics ()
 
void ApplyLinearImpulse (Vector2 impulse)
 
void ApplyLinearImpulse (Vector2 impulse, float maxVelocity)
 Apply an impulse to the body without increasing it's velocity above a specific limit. More...
 
void ApplyLinearImpulse (Vector2 impulse, Vector2 point)
 
void ApplyLinearImpulse (Vector2 impulse, Vector2 point, float maxVelocity)
 Apply an impulse to the body without increasing it's velocity above a specific limit. More...
 
void ApplyForce (Vector2 force, float maxVelocity=NetConfig.MaxPhysicsBodyVelocity)
 
void ApplyForce (Vector2 force, Vector2 point)
 
void ApplyTorque (float torque)
 
bool SetTransform (Vector2 simPosition, float rotation, bool setPrevTransform=true)
 
bool SetTransformIgnoreContacts (Vector2 simPosition, float rotation, bool setPrevTransform=true)
 
void SetPrevTransform (Vector2 simPosition, float rotation)
 
void MoveToTargetPosition (bool lerp=true)
 
void MoveToPos (Vector2 simPosition, float force, Vector2? pullPos=null)
 
void ApplyWaterForces ()
 Applies buoyancy, drag and angular drag caused by water More...
 
void Update ()
 
void UpdateDrawPosition (bool interpolate=true)
 
void CorrectPosition< T > (List< T > positionBuffer, out Vector2 newPosition, out Vector2 newVelocity, out float newRotation, out float newAngularVelocity)
 
void SmoothRotate (float targetRotation, float force=10.0f, bool wrapAngle=true)
 Rotate the body towards the target rotation in the "shortest direction", taking into account the current angular velocity to prevent overshooting. More...
 
void Remove ()
 
void Draw (DeformableSprite deformSprite, Camera cam, Vector2 scale, Color color, bool invert=false)
 
void Draw (SpriteBatch spriteBatch, Sprite sprite, Color color, float? depth=null, float scale=1.0f, bool mirrorX=false, bool mirrorY=false, Vector2? origin=null)
 
void DebugDraw (SpriteBatch spriteBatch, Color color, bool forceColor=false)
 
PosInfo ClientRead (IReadMessage msg, float sendingTime, string parentDebugName)
 

Static Public Member Functions

static float TransformRotation (float rot, float dir)
 
static void RemoveAll ()
 
static bool IsValidShape (float radius, float height, float width)
 
static Shape DefineBodyShape (float radius, float width, float height)
 

Public Attributes

float? PositionSmoothingFactor
 
Submarine Submarine
 

Static Public Attributes

const float MinDensity = 0.01f
 
const float DefaultAngularDamping = 5.0f
 

Protected Attributes

Vector2 prevPosition
 
float prevRotation
 
Vector2? targetPosition
 
float? targetRotation
 

Properties

static List< PhysicsBodyList [get]
 
bool Removed [get]
 
Vector2 LastSentPosition [get]
 
float Height [get]
 
float Width [get]
 
float Radius [get]
 
Shape BodyShape [get]
 
Vector2? TargetPosition [get, set]
 
float? TargetRotation [get, set]
 
Vector2? DrawPosition [get]
 
float DrawRotation [get]
 
float Dir [get, set]
 
bool Enabled [get, set]
 
bool PhysEnabled [get, set]
 
Vector2 SimPosition [get]
 
Vector2 Position [get]
 
Vector2 PrevPosition [get]
 
float Rotation [get]
 
float TransformedRotation [get]
 Takes flipping (Dir) into account. More...
 
Vector2 LinearVelocity [get, set]
 
float AngularVelocity [get, set]
 
float Mass [get]
 
float Density [get]
 
Body FarseerBody [get]
 
object UserData [get, set]
 
float Friction [set]
 
BodyType BodyType [get, set]
 
Category CollisionCategories [get, set]
 
Category CollidesWith [get, set]
 
bool SuppressSmoothRotationCalls [get, set]
 Ignore rotation calls for the rest of this and the next update. Automatically disabled after that. Used for temporarily suppressing the SmoothRotate calls to prevent conflicting or unitentionally amplified rotations. More...
 
Texture2D BodyShapeTexture [get]
 

Detailed Description

Member Enumeration Documentation

◆ Shape

Enumerator
Circle 
Rectangle 
Capsule 
HorizontalCapsule 

Definition at line 86 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

Constructor & Destructor Documentation

◆ PhysicsBody() [1/8]

Barotrauma.PhysicsBody.PhysicsBody ( XElement  element,
float  scale = 1.0f,
bool  findNewContacts = true 
)

◆ PhysicsBody() [2/8]

Barotrauma.PhysicsBody.PhysicsBody ( ColliderParams  cParams,
bool  findNewContacts = true 
)

◆ PhysicsBody() [3/8]

Barotrauma.PhysicsBody.PhysicsBody ( LimbParams  lParams,
bool  findNewContacts = true 
)

◆ PhysicsBody() [4/8]

Barotrauma.PhysicsBody.PhysicsBody ( float  width,
float  height,
float  radius,
float  density,
BodyType  bodyType,
Category  collisionCategory,
Category  collidesWith,
bool  findNewContacts = true 
)

◆ PhysicsBody() [5/8]

Barotrauma.PhysicsBody.PhysicsBody ( Body  farseerBody)

◆ PhysicsBody() [6/8]

Barotrauma.PhysicsBody.PhysicsBody ( ColliderParams  colliderParams,
Vector2  position,
bool  findNewContacts = true 
)

◆ PhysicsBody() [7/8]

Barotrauma.PhysicsBody.PhysicsBody ( LimbParams  limbParams,
Vector2  position,
bool  findNewContacts = true 
)

◆ PhysicsBody() [8/8]

Barotrauma.PhysicsBody.PhysicsBody ( XElement  element,
Vector2  position,
float  scale = 1.0f,
float?  forceDensity = null,
Category  collisionCategory = Physics.CollisionItem,
Category  collidesWith = Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionPlatform,
bool  findNewContacts = true 
)

Member Function Documentation

◆ ApplyForce() [1/2]

void Barotrauma.PhysicsBody.ApplyForce ( Vector2  force,
float  maxVelocity = NetConfig.MaxPhysicsBodyVelocity 
)

◆ ApplyForce() [2/2]

void Barotrauma.PhysicsBody.ApplyForce ( Vector2  force,
Vector2  point 
)

◆ ApplyLinearImpulse() [1/4]

void Barotrauma.PhysicsBody.ApplyLinearImpulse ( Vector2  impulse)

◆ ApplyLinearImpulse() [2/4]

void Barotrauma.PhysicsBody.ApplyLinearImpulse ( Vector2  impulse,
float  maxVelocity 
)

Apply an impulse to the body without increasing it's velocity above a specific limit.

Definition at line 656 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ ApplyLinearImpulse() [3/4]

void Barotrauma.PhysicsBody.ApplyLinearImpulse ( Vector2  impulse,
Vector2  point 
)

◆ ApplyLinearImpulse() [4/4]

void Barotrauma.PhysicsBody.ApplyLinearImpulse ( Vector2  impulse,
Vector2  point,
float  maxVelocity 
)

Apply an impulse to the body without increasing it's velocity above a specific limit.

Definition at line 685 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ ApplyTorque()

void Barotrauma.PhysicsBody.ApplyTorque ( float  torque)

◆ ApplyWaterForces()

void Barotrauma.PhysicsBody.ApplyWaterForces ( )

Applies buoyancy, drag and angular drag caused by water

Definition at line 828 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ ClientRead()

PosInfo Barotrauma.PhysicsBody.ClientRead ( IReadMessage  msg,
float  sendingTime,
string  parentDebugName 
)

◆ CorrectPosition< T >()

void Barotrauma.PhysicsBody.CorrectPosition< T > ( List< T >  positionBuffer,
out Vector2  newPosition,
out Vector2  newVelocity,
out float  newRotation,
out float  newAngularVelocity 
)
Type Constraints
T :PosInfo 

Definition at line 889 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ DebugDraw()

void Barotrauma.PhysicsBody.DebugDraw ( SpriteBatch  spriteBatch,
Color  color,
bool  forceColor = false 
)

◆ DefineBodyShape()

static Shape Barotrauma.PhysicsBody.DefineBodyShape ( float  radius,
float  width,
float  height 
)
static

◆ Draw() [1/2]

void Barotrauma.PhysicsBody.Draw ( DeformableSprite  deformSprite,
Camera  cam,
Vector2  scale,
Color  color,
bool  invert = false 
)

◆ Draw() [2/2]

void Barotrauma.PhysicsBody.Draw ( SpriteBatch  spriteBatch,
Sprite  sprite,
Color  color,
float?  depth = null,
float  scale = 1.0f,
bool  mirrorX = false,
bool  mirrorY = false,
Vector2?  origin = null 
)

◆ GetLocalFront()

Vector2 Barotrauma.PhysicsBody.GetLocalFront ( float?  spritesheetRotation = null)

Returns the farthest point towards the forward of the body. For capsules and circles, the front is at the top. For horizontal capsules, the front is at the right-most point. For rectangles, the front is either at the top or at the right, depending on which one of the two is greater: width or height. The rotation is in radians.

Definition at line 499 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ GetMaxExtent()

float Barotrauma.PhysicsBody.GetMaxExtent ( )

◆ GetSize()

Vector2 Barotrauma.PhysicsBody.GetSize ( )

◆ IsValidShape()

static bool Barotrauma.PhysicsBody.IsValidShape ( float  radius,
float  height,
float  width 
)
static

◆ IsValidValue()

bool Barotrauma.PhysicsBody.IsValidValue ( float  value,
string  valueName,
float  minValue = float.MinValue,
float  maxValue = float.MaxValue 
)

◆ MoveToPos()

void Barotrauma.PhysicsBody.MoveToPos ( Vector2  simPosition,
float  force,
Vector2?  pullPos = null 
)

◆ MoveToTargetPosition()

void Barotrauma.PhysicsBody.MoveToTargetPosition ( bool  lerp = true)

◆ Remove()

void Barotrauma.PhysicsBody.Remove ( )

◆ RemoveAll()

static void Barotrauma.PhysicsBody.RemoveAll ( )
static

◆ ResetDynamics()

void Barotrauma.PhysicsBody.ResetDynamics ( )

◆ SetPrevTransform()

void Barotrauma.PhysicsBody.SetPrevTransform ( Vector2  simPosition,
float  rotation 
)

◆ SetSize()

void Barotrauma.PhysicsBody.SetSize ( Vector2  size)

◆ SetTransform()

bool Barotrauma.PhysicsBody.SetTransform ( Vector2  simPosition,
float  rotation,
bool  setPrevTransform = true 
)

◆ SetTransformIgnoreContacts()

bool Barotrauma.PhysicsBody.SetTransformIgnoreContacts ( Vector2  simPosition,
float  rotation,
bool  setPrevTransform = true 
)

◆ SmoothRotate()

void Barotrauma.PhysicsBody.SmoothRotate ( float  targetRotation,
float  force = 10.0f,
bool  wrapAngle = true 
)

Rotate the body towards the target rotation in the "shortest direction", taking into account the current angular velocity to prevent overshooting.

Parameters
targetRotationDesired rotation in radians
forceHow fast the body should be rotated. Does not represent any real unit, you may want to experiment with different values to get the desired effect.
wrapAngleShould the angles be wrapped. Set to false if it makes a difference whether the angle of the body is 0.0f or 360.0f.

Definition at line 920 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ TransformRotation() [1/2]

static float Barotrauma.PhysicsBody.TransformRotation ( float  rot,
float  dir 
)
static

◆ TransformRotation() [2/2]

float Barotrauma.PhysicsBody.TransformRotation ( float  rotation)

◆ Update()

void Barotrauma.PhysicsBody.Update ( )

◆ UpdateDrawPosition()

void Barotrauma.PhysicsBody.UpdateDrawPosition ( bool  interpolate = true)

Member Data Documentation

◆ DefaultAngularDamping

const float Barotrauma.PhysicsBody.DefaultAngularDamping = 5.0f
static

◆ MinDensity

const float Barotrauma.PhysicsBody.MinDensity = 0.01f
static

◆ PositionSmoothingFactor

float? Barotrauma.PhysicsBody.PositionSmoothingFactor

◆ prevPosition

Vector2 Barotrauma.PhysicsBody.prevPosition
protected

◆ prevRotation

float Barotrauma.PhysicsBody.prevRotation
protected

◆ Submarine

Submarine Barotrauma.PhysicsBody.Submarine

◆ targetPosition

Vector2? Barotrauma.PhysicsBody.targetPosition
protected

◆ targetRotation

float? Barotrauma.PhysicsBody.targetRotation
protected

Property Documentation

◆ AngularVelocity

float Barotrauma.PhysicsBody.AngularVelocity
getset

◆ BodyShape

Shape Barotrauma.PhysicsBody.BodyShape
get

◆ BodyShapeTexture

Texture2D Barotrauma.PhysicsBody.BodyShapeTexture
get

◆ BodyType

BodyType Barotrauma.PhysicsBody.BodyType
getset

◆ CollidesWith

Category Barotrauma.PhysicsBody.CollidesWith
getset

◆ CollisionCategories

Category Barotrauma.PhysicsBody.CollisionCategories
getset

◆ Density

float Barotrauma.PhysicsBody.Density
get

◆ Dir

float Barotrauma.PhysicsBody.Dir
getset

◆ DrawPosition

Vector2? Barotrauma.PhysicsBody.DrawPosition
get

◆ DrawRotation

float Barotrauma.PhysicsBody.DrawRotation
get

◆ Enabled

bool Barotrauma.PhysicsBody.Enabled
getset

◆ FarseerBody

Body Barotrauma.PhysicsBody.FarseerBody
get

◆ Friction

float Barotrauma.PhysicsBody.Friction
set

◆ Height

float Barotrauma.PhysicsBody.Height
get

◆ LastSentPosition

Vector2 Barotrauma.PhysicsBody.LastSentPosition
get

◆ LinearVelocity

Vector2 Barotrauma.PhysicsBody.LinearVelocity
getset

◆ List

List<PhysicsBody> Barotrauma.PhysicsBody.List
staticget

◆ Mass

float Barotrauma.PhysicsBody.Mass
get

◆ PhysEnabled

bool Barotrauma.PhysicsBody.PhysEnabled
getset

◆ Position

Vector2 Barotrauma.PhysicsBody.Position
get

◆ PrevPosition

Vector2 Barotrauma.PhysicsBody.PrevPosition
get

◆ Radius

float Barotrauma.PhysicsBody.Radius
get

◆ Removed

bool Barotrauma.PhysicsBody.Removed
get

◆ Rotation

float Barotrauma.PhysicsBody.Rotation
get

◆ SimPosition

Vector2 Barotrauma.PhysicsBody.SimPosition
get

◆ SuppressSmoothRotationCalls

bool Barotrauma.PhysicsBody.SuppressSmoothRotationCalls
getset

Ignore rotation calls for the rest of this and the next update. Automatically disabled after that. Used for temporarily suppressing the SmoothRotate calls to prevent conflicting or unitentionally amplified rotations.

Definition at line 351 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ TargetPosition

Vector2? Barotrauma.PhysicsBody.TargetPosition
getset

◆ TargetRotation

float? Barotrauma.PhysicsBody.TargetRotation
getset

◆ TransformedRotation

float Barotrauma.PhysicsBody.TransformedRotation
get

Takes flipping (Dir) into account.

Definition at line 264 of file BarotraumaShared/SharedSource/Physics/PhysicsBody.cs.

◆ UserData

object Barotrauma.PhysicsBody.UserData
getset

◆ Width

float Barotrauma.PhysicsBody.Width
get