CreateJoint
Create a PhysicsDistanceJoint in the world. See PhysicsDistanceJoint.Create.
Read time 2 minutesLast updated 12 days ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
CreateJoint(PhysicsDistanceJointDefinition)
Create a PhysicsDistanceJoint in the world. See PhysicsDistanceJoint.Create.
public PhysicsDistanceJoint CreateJoint(PhysicsDistanceJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsDistanceJoint | The created joint. |
Remarks
Use this method to connect two bodies with a distance constraint, keeping them a set distance apart, similarly to a spring or a rope.
Examples
// Connect two existing bodies with a distance joint.using UnityEngine;using Unity.U2D.Physics;public class CreateDistanceJointExample : MonoBehaviour{ void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; PhysicsBody body1 = world.CreateBody(); PhysicsBody body2 = world.CreateBody(); PhysicsDistanceJointDefinition jointDefinition = new PhysicsDistanceJointDefinition { bodyA = body1, bodyB = body2, autoDistance = false, distance = 2f }; PhysicsJoint distanceJoint = world.CreateJoint(jointDefinition); }}
CreateJoint(PhysicsRelativeJointDefinition)
Create a PhysicsRelativeJoint in the world. See PhysicsRelativeJoint.Create.
public PhysicsRelativeJoint CreateJoint(PhysicsRelativeJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsRelativeJoint | The created joint. |
CreateJoint(PhysicsIgnoreJointDefinition)
Create an PhysicsIgnoreJoint in the world. See PhysicsIgnoreJoint.Create.
public PhysicsIgnoreJoint CreateJoint(PhysicsIgnoreJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsIgnoreJoint | The created joint. |
CreateJoint(PhysicsSliderJointDefinition)
Create a PhysicsSliderJoint in the world. See PhysicsSliderJoint.Create.
public PhysicsSliderJoint CreateJoint(PhysicsSliderJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsSliderJoint | The created joint. |
CreateJoint(PhysicsHingeJointDefinition)
Create a PhysicsHingeJoint in the world. See PhysicsHingeJoint.Create.
public PhysicsHingeJoint CreateJoint(PhysicsHingeJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsHingeJoint | The created joint. |
CreateJoint(PhysicsFixedJointDefinition)
Create a PhysicsFixedJoint in the world. See PhysicsFixedJoint.Create.
public PhysicsFixedJoint CreateJoint(PhysicsFixedJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsFixedJoint | The created joint. |
CreateJoint(PhysicsWheelJointDefinition)
Create a PhysicsWheelJoint in the world. See PhysicsWheelJoint.Create.
public PhysicsWheelJoint CreateJoint(PhysicsWheelJointDefinition definition)
Parameters
The joint definition to use.
Returns
Type | Description |
|---|---|
| PhysicsWheelJoint | The created joint. |