Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PhysicsChain

A dedicated shape that produces a chain of shapes connected together to produce a continuous surface. Chain shapes provide a smooth, continuous surface that will not produce "ghost" collisions. A PhysicsChain is automatically destroyed when the body it is in is destroyed. A PhysicsChain cannot exist unattached from a body. This will produce shapes of type PhysicsShape.ShapeType.ChainSegment. Chains are one-sided. A chain has no mass therefore should ideally be used on static bodies. A chain can have a counter-clockwise winding order (normal points right of segment direction). A chain is either a loop or open. A chain must have at least 4 points. The distance between any two points must be greater than _linearSlop. A chain should not self intersect (this is not validated). An open chain has no collision on the first and final edge. You may overlap two open chains on their first three and/or last three points to get smooth collision.
Read time 5 minutesLast updated 7 days ago

Definition

public readonly struct PhysicsChain : IEquatable<PhysicsChain>

Constructors

Constructor

Description

PhysicsChain(Unity.U2D.Physics.PhysicsHandle)Create a chain from a physics handle.

Properties

Property

Description

aabbGet the world AABB that bounds this chain. The bounds of the shape is inflated slightly due to speculative collision detection. The inflation is smaller on Static shape types however it is not zero due to time-of-impact collision detection. If an exact AABB is required then you can retrieve that via the shape geometry.
bodyThe body which the chain is attached to.
bouncinessThe bounciness of the chain. Usually this is within the range [0, 1]. Values higher than 1 will result in energy being added which can lead to an unstable simulation.
bouncinessMixingDefines the method used when mixing the bounciness values of two shapes to form a shape contact. This is assigned to the current _surfaceMaterial.
callbackTargetGet/Set the Object that callbacks for the shapes owned by this chain will be sent to. Care should be taken with any Object assigned as a callback target that isn't a Object as this assignment will not in itself keep the object alive and can be garbage collected. To avoid this, you should have at least a single reference to the object in your code. To remove the object assigned here, set the callback target to NULL.
frictionThe friction of the owned chain shapes. Usually this is within the range [0, 1]. Values higher than 1 will result in energy being added which can lead to an unstable simulation.
frictionMixingDefines the method used when mixing the friction values of two shapes to form a shape contact. This is assigned to the current _surfaceMaterial.
isOwnedGet if the chain is owned. See PhysicsChain.SetOwner.
isValidCheck if the shape is valid.
ownerUserDataGet PhysicsUserData that can be used for any purpose, typically by the owner only.
physicsHandleGet the physics handle.
segmentCountGet the number of Chain segments that this chain has created and owns. See PhysicsShape.ShapeType.ChainSegment.
userDataGet/Set PhysicsUserData that can be used for any purpose. The physics system doesn't use this data, it is entirely for custom use.
worldGet the world the chain is attached to.
worldDrawingControls whether this chain is automatically drawn when the world is drawn.

Methods

Method

Description

CastRayCheck if a ray intersects the chain. See PhysicsQuery.CastResult.
CastShapeCalculate if a cast shape intersects the chain. See PhysicsQuery.CastShapeInput and PhysicsQuery.CastResult.
ClosestPointCalculate the closest point on this chain to the specified point.
DestroyDestroy the PhysicsChain and all the PhysicsShape.ShapeType.ChainSegment it owns. If the object is owned with PhysicsChain.SetOwner then you must provide the owner key it returned. Failing to do so will return a warning and the chain will not be destroyed. The lifetime of the specified owner object is not linked to this chain i.e. this chain will still be owned by the owner object, even if it is destroyed. This is the only way to destroy shapes of type PhysicsShape.ShapeType.ChainSegment if they were created by a PhysicsChain.
GetOwnerGet the owner object associated with this chain as specified using PhysicsChain.SetOwner.
GetSegmentIndexGet the index of the specified Chain Segment PhysicsShape.
GetSegmentsGet all the Chain segments that this chain has created and owns.
SetOwnerSet the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. It is also valid to not specify an owner object (NULL) to simply gain an owner key however it can be useful, if simply for debugging purposes and discovery, to know which object is the owner.
SetOwnerUserDataSet PhysicsUserData that can be used for any purpose, typically by the owner only.
UpdateVerticesUpdate the existing ChainSegment shapes with the provided vertices. Modifying the vertices will cause contacts to be recalculated however it may cause overlaps and/or collision tunnelling if not used carefully. The number of vertices provided and looping option should be the same as was used when the Chain was originally created. Any mismatch between the two will result in a warning.

Static Methods

Method

Description

CreateCreate a Chain of multiple shapes attached to the specified body which itself is within a world.
SetOwnerSet the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. Whilst it is valid to not specify an owner object (NULL), it is recommended for debugging purposes.