---
title: SolvePositionConstraint
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/core/solvepositionconstraint
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/core/solvepositionconstraint.md
last_updated: 2026-11-30
generated_at: 2026-11-30T21:08:38.146Z
locale: en-us
---

# SolvePositionConstraint

> Position constraint solver moves a constrained bone to follow its source objects.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Animations](/engine/7000.0/script-reference/unity/animations.md)
* **Assembly:** [UnityEngine.AnimationCoreModule](/engine/7000.0/script-reference/modules/unityengine-animationcoremodule.md)

## SolvePositionConstraint(AnimationStream, PositionConstraintData, float)

Position constraint solver moves a constrained bone to follow its source objects.

```csharp
public static void SolvePositionConstraint(ref AnimationStream stream, in Core.PositionConstraintData data, float weight)
```

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The animation stream to apply the solver to.**** (\[PositionConstraintData]\(/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata)): The solver settings. See [Core.PositionConstraintData](/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata.md).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The overall weight of the solver, clamped to the range from 0 to 1. A weight of 0 leaves the constrained bone unchanged, and a weight of 1 applies the full constraint. Intermediate values blend linearly.

## SolvePositionConstraint(AnimationStream, PositionConstraintData, float3, float3, float)

Applies a position constraint to a bone from a single source.

```csharp
public static void SolvePositionConstraint(ref AnimationStream stream, in Core.PositionConstraintData data, float3 sourcePosition, float3 sourceOffset, float weight)
```

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The animation stream to apply the solver to.**** (\[PositionConstraintData]\(/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata)): The solver settings. The method uses only [Core.PositionConstraintData.Index](/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata/index.md), [Core.PositionConstraintData.LocalAxesMask](/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata/localaxesmask.md), and [Core.PositionConstraintData.LocalOffset](/engine/7000.0/script-reference/unity/animations/core/positionconstraintdata/localoffset.md), and ignores the source arrays.**** (\[float3]\(/engine/7000.0/script-reference/unity/mathematics/float3)): The source position, in character space. To follow a world-space target, convert it first with `math.transform(math.inverse(characterToWorld), worldPosition)`.**** (\[float3]\(/engine/7000.0/script-reference/unity/mathematics/float3)): The additional translation offset to apply on the source position.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The overall weight of the solver, clamped to the range from 0 to 1. A weight of 0 leaves the constrained bone unchanged, and a weight of 1 applies the full constraint. Intermediate values blend linearly.

### Remarks

Use this overload when the constraint has one source. It gives the same result as [Core.SolvePositionConstraint](/engine/7000.0/script-reference/unity/animations/core/solvepositionconstraint.md) with one source of weight 1, and you don't need to allocate a [NativeArray\<T>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) for the sources. The method ignores the source arrays in `data`.

The following example uses the `Unity.Animations` and `Unity.Mathematics` namespaces. It converts world-space targets to character space and passes them to the single-source solvers.

### Examples

```csharp
// This example makes a bone aim at a target that lives in world space, for example the position of another entity.
// The constraint solvers work in character space, so the example converts the target first. characterToWorld
// is the character's LocalToWorld transform. Its inverse takes a world-space point to character space.
public static void AimAtWorldTarget(
    ref AnimationStream stream,
    int boneIndex,
    float3 aimAxis,
    RigidTransform characterToWorld,
    float3 worldTarget,
    float weight)
{
    float3 characterTarget = math.transform(math.inverse(characterToWorld), worldTarget);

    // Start from the default settings. The solvers that take a single source ignore the source arrays,
    // so there is nothing to allocate.
    Core.AimConstraintData data = Core.AimConstraintData.Default();
    data.Index = boneIndex;
    data.AimAxis = aimAxis;

    Core.SolveAimConstraint(ref stream, data, characterTarget, quaternion.identity, weight);
}

// A parent constraint follows a world-space transform the same way: multiply the target by the inverse of
// characterToWorld to get a character-space transform.
public static void FollowWorldTransform(
    ref AnimationStream stream,
    int boneIndex,
    RigidTransform characterToWorld,
    RigidTransform worldTarget,
    float weight)
{
    RigidTransform characterTarget = math.mul(math.inverse(characterToWorld), worldTarget);

    Core.ParentConstraintData data = Core.ParentConstraintData.Default();
    data.Index = boneIndex;

    Core.SolveParentConstraint(ref stream, data, characterTarget, RigidTransform.identity, weight);
}

// The position and rotation constraints convert a world-space target the same way.
public static void MoveToWorldPosition(
    ref AnimationStream stream,
    int boneIndex,
    RigidTransform characterToWorld,
    float3 worldPosition,
    float weight)
{
    float3 characterPosition = math.transform(math.inverse(characterToWorld), worldPosition);

    Core.PositionConstraintData data = Core.PositionConstraintData.Default();
    data.Index = boneIndex;

    Core.SolvePositionConstraint(ref stream, data, characterPosition, float3.zero, weight);
}

public static void MatchWorldRotation(
    ref AnimationStream stream,
    int boneIndex,
    RigidTransform characterToWorld,
    quaternion worldRotation,
    float weight)
{
    quaternion characterRotation = math.mul(math.inverse(characterToWorld.rot), worldRotation);

    Core.RotationConstraintData data = Core.RotationConstraintData.Default();
    data.Index = boneIndex;

    Core.SolveRotationConstraint(ref stream, data, characterRotation, quaternion.identity, weight);
}
```
