Kinematics for Unity
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
Passer.Kinematics.RotationalJoint Class Reference

Unity

A RotationalJoint lets transform rotate around a defined axis.

Inspector

The range of motion can be limited by a minimum and maximum angle. Chains of (rotational) joins can be created with support for inverse kinematics.

Scene

In the scene view, the axis and limits are visualized when the object is selected. The axis is a yellow line from the transform's position in the direction of the axis. When the joint has limits, the minimum and maximum angle are drawn as circle segments. The picture above shows a cube with a RotationalJoint with a limit of -90 and 90 degrees rotation around the local Y axis.

Inverse Kinematics

Inverse kinematics is built-in and works when you have a kinematic chain of kinematic joints parented to each other. Only the last child should have a target assigned. Example:

Rotational Joint 1 [ target = null ]
-> Rotational Joint 2 [ target = null ]
   -> Rotational Joint 3 [ target != null ]

The target's movements of the end effector (Rotational Joint 3 in the example) will then propagate up through the rotational joints on the parent transforms. The rotational joints do not have to be direct children of each other for this to work. Example:

Inheritance diagram for Passer.Kinematics.RotationalJoint:
Passer.Kinematics.KinematicJoint

Public Member Functions

override void DetermineBaseTargetVector (Vector3 targetPosition, Quaternion targetRotation, bool findParent=true, bool traverseWelds=true)
 
override void Update ()
 
override void CheckConstraints ()
 Check the rotation limits and correct the rotation if necessary More...
 
void CheckConstraints (Quaternion deltaRotation)
 
override void UpdateValue (float value)
 Update the angle of this RotationalJoint More...
 
virtual void FindParentConstraint ()
 
virtual void UpdateKinematics ()
 
virtual void UpdateInverseKinematics (KinematicJoint childJoint)
 
virtual Vector3 CalculateTargetPosition ()
 
virtual void CleanupTransmissions ()
 Removes any transmissions which have an empty otherJoint More...
 
void AddTransmission (Transmission newTransmission)
 

Public Attributes

float maxSpeed = 500
 Maximum rotation speed in degrees per second More...
 
float acceleration = 1000
 Acceleration in degrees per second per second More...
 
float targetAngle
 
GameObjectEventHandlers gameObjectEvents
 Event Handlers for the lifecycle of the GameObject More...
 
FloatEventHandlers angleEvents
 Event handles based on the angle values More...
 
KinematicJoint parentJoint
 The parent constraint in a kinematic chain More...
 
bool hasLimits = false
 The movments relative to axis are limited More...
 
bool leading = true
 
Transform target
 The target Transform for the movements More...
 
Vector3 targetPosition = Vector3.zero
 
Quaternion targetRotation = Quaternion.identity
 
Vector3 axis = Vector3.up
 The local axis of the joint More...
 
KinematicJoint sourceJoint
 
Transmission[] transmissions
 

Protected Member Functions

override void CalculateTarget (Vector3 targetPosition, Quaternion targetRotation)
 
override Quaternion CalculateTargetRotation (Vector3 parentPosition)
 
override void Actuate ()
 
float UpdateSpeed (float acceleration, float targetSpeed, float distance=-1)
 
Quaternion GetCorrectionAxisRotation ()
 
Quaternion GetCorrectionAxisRotation (Quaternion deltaRotation)
 
override void UpdateTransmissionIK ()
 
override void TransmissionForward ()
 
override void UpdateEvents ()
 
Vector3 GetLocalVector (Vector3 worldVector)
 
virtual void Awake ()
 
PureGetComponentInChildren< T > ()
 
virtual void Start ()
 
virtual void LateUpdate ()
 
virtual void CheckTargetChange ()
 
Vector3 CalculateTargetPosition (Vector3 childTargetPosition)
 
void RemoveTransmission (KinematicJoint kinematicJoint)
 
bool HasTransmission ()
 

Protected Attributes

Quaternion _baseRotation = Quaternion.identity
 
float currentSpeed = 0
 
float currentAngle
 
float angleValue
 
IWeld weld = null
 
Vector3 baseVectorLocal = Vector3.zero
 
Quaternion baseRotation = Quaternion.identity
 The base rotation for the limites More...
 
Quaternion localBaseRotation = Quaternion.identity
 
Vector3 basePosition = Vector3.zero
 The base position for the limits More...
 
float lastTargetJointAngle = 0
 

Properties

override float minimum [get, set]
 The minimum angle in degrees around the rotationAxis More...
 
override float maximum [get, set]
 The maximum angle in degrees around the rotationAxis More...
 
float angle [get]
 The angle of this Transform along the rotationAxis More...
 
float fraction [get]
 The fraction (-1..0..1) between the limits of the joint More...
 
Quaternion rotation [get, set]
 The rotation of the Transform in world space More...
 
Quaternion localRotation [get, set]
 The rotation of the Transform in local space More...
 
Vector3 targetVector [get]
 The vector from the transform position to the target in world coordinates More...
 
Vector3 baseVector [get]
 The vector from the transform to the target position at start in world coordinates More...
 
Vector3 worldAxis [get]
 The world axis of the joint More...
 

Member Function Documentation

◆ CheckConstraints()

override void Passer.Kinematics.RotationalJoint.CheckConstraints ( )
virtual

Check the rotation limits and correct the rotation if necessary

Reimplemented from Passer.Kinematics.KinematicJoint.

◆ UpdateValue()

override void Passer.Kinematics.RotationalJoint.UpdateValue ( float  value)
virtual

Update the angle of this RotationalJoint

Parameters
valueThe desired rotation around axis in degrees

Reimplemented from Passer.Kinematics.KinematicJoint.

◆ CleanupTransmissions()

virtual void Passer.Kinematics.KinematicJoint.CleanupTransmissions ( )
virtualinherited

Removes any transmissions which have an empty otherJoint

Member Data Documentation

◆ maxSpeed

float Passer.Kinematics.RotationalJoint.maxSpeed = 500

Maximum rotation speed in degrees per second

This is only applicable when the joint has a target or when it is part of a kinematic chain. Note that the Inverse Kinematics can become unstable when this is set to high speeds

◆ acceleration

float Passer.Kinematics.RotationalJoint.acceleration = 1000

Acceleration in degrees per second per second

This is only applicable when the joint has a target or when it is part of a kinematic chain.

◆ gameObjectEvents

GameObjectEventHandlers Passer.Kinematics.RotationalJoint.gameObjectEvents
Initial value:
= new GameObjectEventHandlers() {
label = "GameObject",
tooltip = "Call functions based on the GameObject life cycle",
id = 0,
eventTypeLabels = new string[] {
"Never",
"Start",
"On Destroy",
"Update",
" ",
" ",
" "
}
}

Event Handlers for the lifecycle of the GameObject

◆ angleEvents

FloatEventHandlers Passer.Kinematics.RotationalJoint.angleEvents
Initial value:
= new FloatEventHandlers() {
label = "Angle",
tooltip = "Call functions based on the angle of the object",
id = 1,
eventTypeLabels = new string[] {
"Never",
"On Min",
"On Max",
"While Min",
"While Max",
"On Change",
"Continuous"
},
}

Event handles based on the angle values

These are especially conventient for doing thinge when the minimum or maximum angle value has been reached

◆ parentJoint

KinematicJoint Passer.Kinematics.KinematicJoint.parentJoint
inherited

The parent constraint in a kinematic chain

◆ hasLimits

bool Passer.Kinematics.KinematicJoint.hasLimits = false
inherited

The movments relative to axis are limited

◆ baseRotation

Quaternion Passer.Kinematics.KinematicJoint.baseRotation = Quaternion.identity
protectedinherited

The base rotation for the limites

◆ basePosition

Vector3 Passer.Kinematics.KinematicJoint.basePosition = Vector3.zero
protectedinherited

The base position for the limits

◆ target

Transform Passer.Kinematics.KinematicJoint.target
inherited

The target Transform for the movements

The kinematic object tries to follow the target as far this is possible within the set constrains. For rotations: the target rotation is used when the target position is equal to the object position when the target is attached to the object. Otherwise the target position is used for rotations.

◆ axis

Vector3 Passer.Kinematics.KinematicJoint.axis = Vector3.up
inherited

The local axis of the joint

Property Documentation

◆ minimum

override float Passer.Kinematics.RotationalJoint.minimum
getset

The minimum angle in degrees around the rotationAxis

When this is zero, the local rotation is locked. This value should be less than zero.

◆ maximum

override float Passer.Kinematics.RotationalJoint.maximum
getset

The maximum angle in degrees around the rotationAxis

When this is zero, the local rotation is locked. This value should be greater than zero

◆ angle

float Passer.Kinematics.RotationalJoint.angle
get

The angle of this Transform along the rotationAxis

◆ fraction

float Passer.Kinematics.RotationalJoint.fraction
get

The fraction (-1..0..1) between the limits of the joint

This value will return -1 when the angle is at its minimum and 1 when it is at the maximum. When it is at the origin, return 0. Angles in between these points will be interpolated. This will always return 0 when the joint has no limits. Note that this is not uniform when the minimum and maximum have different values besides the sign.

◆ rotation

Quaternion Passer.Kinematics.RotationalJoint.rotation
getset

The rotation of the Transform in world space

Using this rotation instead of the transform.rotation ensures that the rotation is immediately corrected based on the constraints

◆ localRotation

Quaternion Passer.Kinematics.RotationalJoint.localRotation
getset

The rotation of the Transform in local space

Using this rotation instead of the transform.localRotation ensures that the rotation is immediately corrected based on the constraints

◆ targetVector

Vector3 Passer.Kinematics.KinematicJoint.targetVector
getinherited

The vector from the transform position to the target in world coordinates

◆ baseVector

Vector3 Passer.Kinematics.KinematicJoint.baseVector
getinherited

The vector from the transform to the target position at start in world coordinates

This will be zero vector when the target is not set. This will change when the target is changed

◆ worldAxis

Vector3 Passer.Kinematics.KinematicJoint.worldAxis
getinherited

The world axis of the joint


The documentation for this class was generated from the following file: