Version: 2022.2
LanguageEnglish
  • C#

Physics2D

class in UnityEngine

/

Implemented in:UnityEngine.Physics2DModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Global settings and helpers for 2D physics.

Static Properties

AllLayersLayer mask constant that includes all layers.
angularSleepToleranceA Rigidbody cannot sleep if its angular velocity is above this tolerance threshold.
autoSyncTransformsSet whether to automatically sync changes to the Transform component with the physics engine.
baumgarteScaleThe scale factor that controls how fast overlaps are resolved.
baumgarteTOIScaleThe scale factor that controls how fast TOI overlaps are resolved.
callbacksOnDisableUse this to control whether or not the appropriate OnCollisionExit2D or OnTriggerExit2D callbacks should be called when a Collider2D is disabled.
defaultContactOffsetThe default contact offset of the newly created Colliders.
defaultPhysicsSceneThe PhysicsScene2D automatically created when Unity starts.
DefaultRaycastLayersLayer mask constant that includes all layers participating in raycasts by default.
gravityAcceleration due to gravity.
IgnoreRaycastLayerLayer mask constant for the default layer that ignores raycasts.
jobOptionsA set of options that control how physics operates when using the job system to multithread the physics simulation.
linearSleepToleranceA rigid-body cannot sleep if its linear velocity is above this tolerance.
maxAngularCorrectionThe maximum angular position correction used when solving constraints. This helps to prevent overshoot.
maxLinearCorrectionThe maximum linear position correction used when solving constraints. This helps to prevent overshoot.
MaxPolygonShapeVerticesThe maximum number of vertices allowed per primitive polygon shape type (PhysicsShapeType2D.Polygon). (Read Only)
maxRotationSpeedThe maximum angular speed of a rigid-body per physics update. Increasing this can cause numerical problems.
maxTranslationSpeedThe maximum linear speed of a rigid-body per physics update. Increasing this can cause numerical problems.
positionIterationsThe number of iterations of the physics solver when considering objects' positions.
queriesHitTriggersDo raycasts detect Colliders configured as triggers?
queriesStartInCollidersSet the raycasts or linecasts that start inside Colliders to detect or not detect those Colliders.
reuseCollisionCallbacksDetermines whether the garbage collector should reuse only a single instance of a Collision2D type for all collision callbacks.
simulationModeControls when Unity executes the 2D physics simulation.
timeToSleepThe time in seconds that a rigid-body must be still before it will go to sleep.
velocityIterationsThe number of iterations of the physics solver when considering objects' velocities.
velocityThresholdAny collisions with a relative linear velocity below this threshold will be treated as inelastic.

Static Methods

BoxCastCasts a box against Colliders in the Scene, returning the first Collider to contact with it.
BoxCastAllCasts a box against Colliders in the Scene, returning all Colliders that contact with it.
BoxCastNonAllocCasts a box into the Scene, returning Colliders that contact with it into the provided results array. Note: This method will be deprecated in a future build and it is recommended to use BoxCast instead.
CapsuleCastCasts a capsule against Colliders in the Scene, returning the first Collider to contact with it.
CapsuleCastAllCasts a capsule against Colliders in the Scene, returning all Colliders that contact with it.
CapsuleCastNonAllocCasts a capsule into the Scene, returning Colliders that contact with it into the provided results array. Note: This method will be deprecated in a future build and it is recommended to use CapsuleCast instead.
CircleCastCasts a circle against Colliders in the Scene, returning the first Collider to contact with it.
CircleCastAllCasts a circle against Colliders in the Scene, returning all Colliders that contact with it.
CircleCastNonAllocCasts a circle into the Scene, returning Colliders that contact with it into the provided results array. Note: This method will be deprecated in a future build and it is recommended to use CircleCast instead.
ClosestPointReturns a point on the perimeter of the Collider that is closest to the specified position.
DistanceCalculates the minimum distance between two Colliders.
GetContactsRetrieves all Colliders in contact with the Collider.
GetIgnoreCollisionChecks whether the collision detection system will ignore all collisions/triggers between collider1 and collider2 or not.
GetIgnoreLayerCollisionChecks whether collisions between the specified layers be ignored or not.
GetLayerCollisionMaskGet the collision layer mask that indicates which layer(s) the specified layer can collide with.
GetRayIntersectionCast a 3D ray against the Colliders in the Scene returning the first Collider along the ray.
GetRayIntersectionAllCast a 3D ray against the Colliders in the Scene returning all the Colliders along the ray.
GetRayIntersectionNonAllocCast a 3D ray against the Colliders in the Scene returning the Colliders along the ray. Note: This method will be deprecated in a future build and it is recommended to use GetRayIntersection instead.
IgnoreCollisionMakes the collision detection system ignore all collisions/triggers between collider1 and collider2.
IgnoreLayerCollisionChoose whether to detect or ignore collisions between a specified pair of layers.
IsTouchingChecks whether the passed Colliders are in contact or not.
IsTouchingLayersChecks whether the Collider is touching any Colliders on the specified layerMask or not.
LinecastCasts a line segment against Colliders in the Scene.
LinecastAllCasts a line against Colliders in the Scene.
LinecastNonAllocCasts a line against Colliders in the Scene. Note: This method will be deprecated in a future build and it is recommended to use Linecast instead.
OverlapAreaChecks if a Collider falls within a rectangular area.
OverlapAreaAllGet a list of all Colliders that fall within a rectangular area.
OverlapAreaNonAllocGet a list of all Colliders that fall within a specified area. Note: This method will be deprecated in a future build and it is recommended to use OverlapArea instead.
OverlapBoxChecks if a Collider falls within a box area.
OverlapBoxAllGet a list of all Colliders that fall within a box area.
OverlapBoxNonAllocGet a list of all Colliders that fall within a box area. Note: This method will be deprecated in a future build and it is recommended to use OverlapBox instead.
OverlapCapsuleChecks if a Collider falls within a capsule area.
OverlapCapsuleAllGet a list of all Colliders that fall within a capsule area.
OverlapCapsuleNonAllocGet a list of all Colliders that fall within a capsule area. Note: This method will be deprecated in a future build and it is recommended to use OverlapCapsule instead.
OverlapCircleChecks if a Collider falls within a circular area.
OverlapCircleAllGet a list of all Colliders that fall within a circular area.
OverlapCircleNonAllocGet a list of all Colliders that fall within a circular area. Note: This method will be deprecated in a future build and it is recommended to use OverlapCircle instead.
OverlapColliderGets a list of all Colliders that overlap the given Collider.
OverlapPointChecks if a Collider overlaps a point in space.
OverlapPointAllGet a list of all Colliders that overlap a point in space.
OverlapPointNonAllocGet a list of all Colliders that overlap a point in space. Note: This method will be deprecated in a future build and it is recommended to use OverlapPoint instead.
RaycastCasts a ray against Colliders in the Scene.
RaycastAllCasts a ray against Colliders in the Scene, returning all Colliders that contact with it.
RaycastNonAllocCasts a ray into the Scene. Note: This method will be deprecated in a future build and it is recommended to use Raycast instead.
SetLayerCollisionMaskSet the collision layer mask that indicates which layer(s) the specified layer can collide with.
SimulateSimulate physics in the Scene.
SyncTransformsSynchronizes.