# CCPhysicsJoint Class Reference

Inherits from | NSObject
Declared in | CCPhysicsJoint.h

## Overview

CCPhysicsJoints hold two CCPhysicsBodies together in some way like a joint between bones or a hinge on a door. Joints work in a fairly automatic fashion. They are active from the moment they are created. When you are done with a joint you invalidate it in order to disable it. Joints cannot be reactivated once they are invalidated.

## Tasks

### Creating a CCPhysicsJoint Object

- `+ connectedPivotJointWithBodyA:bodyB:anchorA:`
- `+ connectedDistanceJointWithBodyA:bodyB:anchorA:anchorB:`
- `+ connectedDistanceJointWithBodyA:bodyB:anchorA:anchorB:minDistance:maxDistance:`
- `+ connectedSpringJointWithBodyA:bodyB:anchorA:anchorB:restLength:stiffness:damping:`
- `+ connectedRotarySpringJointWithBodyA:bodyB:restAngle:stifness:damping:`
- `+ connectedMotorJointWithBodyA:bodyB:rate:`
- `+ connectedRotaryLimitJointWithBodyA:bodyB:min:max:`
- `+ connectedRatchetJointWithBodyA:bodyB:phase:ratchet:`

### Accessing Physics Joint Attributes

- `bodyA` property
- `bodyB` property
- `maxForce` property
- `collideBodies` property
- `impulse` property
- `breakingForce` property
- `valid` property
- `– invalidate`

## Properties

### bodyA

The first body this joint is attached to.

`@property (nonatomic, readonly) CCPhysicsBody *bodyA`

#### Declared In

`CCPhysicsJoint.h`

### bodyB

The second body this joint is attached to.

`@property (nonatomic, readonly) CCPhysicsBody *bodyB`

#### Declared In

`CCPhysicsJoint.h`

### breakingForce

Maximum force that can be applied before the joint disables itself. Defaults to INFINITY To avoid problems with solver accuracy, make sure that this value is lower than CCPhysicsJoint.maxForce.

`@property (nonatomic, assign) CGFloat breakingForce`

#### Declared In

`CCPhysicsJoint.h`

### collideBodies

Whether or not the connected bodies are allowed to collide with each other. Defaults to YES.

`@property (nonatomic, assign) BOOL collideBodies`

#### Declared In

`CCPhysicsJoint.h`

### impulse

Depending on the joint, either the magnitude of the linear or angular impulse that this joint applied on the previous fixed time step.

`@property (nonatomic, readonly) CGFloat impulse`

#### Declared In

`CCPhysicsJoint.h`

### maxForce

Maxium foce this joint is allowed to use. Defaults to INFINITY.

`@property (nonatomic, assign) CGFloat maxForce`

#### Declared In

`CCPhysicsJoint.h`

### valid

Check if the joint is still valid and active.

`@property (nonatomic, readonly) BOOL valid`

#### Declared In

`CCPhysicsJoint.h`

## Class Methods

### connectedDistanceJointWithBodyA:bodyB:anchorA:anchorB:

Creates and returns a pivot joint between the two bodies and keeps the distance of the two anchor points constant. The anchor points are specified in the coordinates of the node that the bodies are attached to. The distance between the anchor points will be calculated when the joint first becomes active.

`+ (CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

anchorA

  Anchor point A.

anchorB

  Anchor point B.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedDistanceJointWithBodyA:bodyB:anchorA:anchorB:minDistance:maxDistance:

Creates and returns a pivot joint between the two bodies and keeps the distance of the two anchor points within the range. The anchor points are specified in the coordinates of the node that the bodies are attached to.

`+ (CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB minDistance:(CGFloat)min maxDistance:(CGFloat)max`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

anchorA

  Anchor point A.

anchorB

  Anchor point B.

min

  The minimum distance to allow between the anchor points.

max

  The maximum distance to allow between the anchor points.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedMotorJointWithBodyA:bodyB:rate:

Creates and returns a Motor joint between the two bodies. No anchor points are specified as this joint can be used in conjunction with a pivot joint to make a motor around a pivot point.

`+ (CCPhysicsJoint *)connectedMotorJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB rate:(CGFloat)rate`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

rate

  Rate at which the rotate relative to each other. Negative values to reverse direction.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedPivotJointWithBodyA:bodyB:anchorA:

Creates and returns a pivot joint object between the two bodies specified. The pivot point is specified in the coordinates of the node that bodyA is attached to.

`+ (CCPhysicsJoint *)connectedPivotJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

anchorA

  Anchor point A.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedRatchetJointWithBodyA:bodyB:phase:ratchet:

Creates and returns ratchet jointwhereby the angle of rotation between too bodies can go forwards smoothely, but the backwards motion is clipped at ‘ratchet’ intervals. No anchor points are specified as this joint can be used in conjunction with a pivot joint to ratchet its range of motion.

`+ (CCPhysicsJoint *)connectedRatchetJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB phase:(CGFloat)phase ratchet:(CGFloat)ratchet`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

phase

  Phase angle in Radians [0, 2 PI] describing where within the rathet interval the joint is located.

ratchet

  Ratchet interval angle in radians.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedRotaryLimitJointWithBodyA:bodyB:min:max:

Creates and returns joint whereby the angle of rotation between too bodies is limited. No anchor points are specified as this joint can be used in conjunction with a pivot joint to make the pivots range of motion limited.

`+ (CCPhysicsJoint *)connectedRotaryLimitJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB min:(CGFloat)min max:(CGFloat)max`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

min

  Minimum angle in radians.

max

  Maximum angle in radians.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedRotarySpringJointWithBodyA:bodyB:restAngle:stifness:damping:

Creates and returns a rotary spring joint between the two bodies. No anchor points are specified as this joint can be used in conjunction with a pivot joint to make a springing pivot joint.

`+ (CCPhysicsJoint *)connectedRotarySpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB restAngle:(CGFloat)restAngle stifness:(CGFloat)stiffness damping:(CGFloat)damping`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

restAngle

  Rest angle.

stiffness

  Spring stiffness.

damping

  Sprin damping.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

### connectedSpringJointWithBodyA:bodyB:anchorA:anchorB:restLength:stiffness:damping:

Creates and returns a spring joint between the two bodies at the specified anchor points. The anchor points are specicied in the coordinates of the node that he bodies are attached to.

`+ (CCPhysicsJoint *)connectedSpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB restLength:(CGFloat)restLength stiffness:(CGFloat)stiffness damping:(CGFloat)damping`

#### Parameters

bodyA

  Body A.

bodyB

  Body B.

anchorA

  Anchor point A.

anchorB

  Anchor point B.

restLength

  Rest Length.

stiffness

  Spring stiffness.

damping

  Sprin damping.

#### Return Value

The CCPhysicsJoint Object.

#### Declared In

`CCPhysicsJoint.h`

## Instance Methods

### invalidate

Disable the joint and remove it from the simulation.

`- (void)invalidate`

#### Declared In

`CCPhysicsJoint.h`