Distance Constraint

Last updated 2 months ago

The Distance Constraint forces its owner to stay either closer than, further than, or exactly at a specific distance from a target object, regardless of their hierarchical relationships.

To add a Distance Constraint, select an object and use the plus in the Constraints section of the Inspector.

Target

Set the object that will be the target for the Distance Constraint.

Distance

This is the distance that the owner will be constrained from the Target. In the image below, it is represented by the radius of the constraining sphere.

A constraining sphere (outline) is drawn on the stage.

Mode

The Mode defines how to use the constraint sphere defined by the Distance setting.

Closer Than

The owner is constrained closer than the Distance setting. In other words, the owner is constrained inside the constraining sphere.

Closer Than

Further Than

The owner is constrained further than the Distance setting. In other words, the owner is constrained outside the constraining sphere.

Exactly

The owner is constrained exactly at the distance of the constraining sphere.

Exactly

Use Current Distance

The Use Current Distance button updates the Distance setting to the current distance of the owner to the Target.

Strength

The Strength property allows you to choose how much of the source's transformation properties should affect your object's original transformation properties.

A Strength of 1 will make all your object's properties match exactly the properties of the source object.

A Strength of 0 will effectively turn off this constraint's effect, leaving your object with its original Position, Rotation, and Scale values.

Any Strength in between 0 and 1 will modulate between the object's original properties and the source's properties.

Transform Space

Source Space

Choose whether this constraint should use World or Local coordinates for the Source Space.

Destination Space

Choose whether this constraint should use World or Local coordinates for the Destination Space.

Controlling Facial Features Example

Multiple constraints can be used to control the position of a character's facial features. Translation Constraints are placed on the eyes, the nose, the mouth, and other facial features so that they all move with one target node. Moving that one single node controls all the facial features. By setting different Strength values on the constraints, the different facial features can move more or less, creating the a parallax effect, or an illusion of depth.

Setting a Distance Constraint on the target node that's controlling the facial features can prevent us from moving the target too far, which could cause the facial features to move off the face (thus breaking the illusion of depth and our character).

This is particularly useful if your character's facial features need to respond to some kind of input from a user in your game or app.

Keep in mind that each constraint you add to your system adds a little bit of complexity and requires more processing power. In this example, if you don't need a user to control the facial features, then it might be better to save the resources and just make sure you position the target in a way that do