TargetJoint2D
The joint attempts to move a Rigidbody2D to a specific target position.
Read time 7 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
- Inherits from: Joint2D
public sealed class TargetJoint2D : Joint2D
Remarks
This joint is the only joint that doesn't connect two Rigidbody2D together. Instead, it only operates on the single body it is connected to.
When connected, it will attempt to move the body to a specified TargetJoint2D.target position. When setting a target you can also set the TargetJoint2D.anchor position which is a point relative to the Rigidbody2D where forces will be applied.
The joint moves the body using a configurable spring that has a force limit.
An example usage for this joint might be to enable Collider2D to be dragged, selecting an anchor point and moving the body to the position under the mouse.
Properties
Property | Description |
|---|---|
| anchor | The local-space anchor on the rigid-body the joint is attached to. |
| autoConfigureTarget | Should the target be calculated automatically? |
| dampingRatio | The amount by which the target spring force is reduced in proportion to the movement speed. |
| frequency | The frequency at which the target spring oscillates around the target position. |
| maxForce | The maximum force that can be generated when trying to maintain the target joint constraint. |
| target | The world-space position that the joint will attempt to move the body to. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |