---
title: SolveRotationConstraint
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/solverotationconstraint
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/core/solverotationconstraint.md
last_updated: 2026-11-30
generated_at: 2026-11-30T20:52:45.722Z
locale: en-us
---

# SolveRotationConstraint

> Rotation constraint solver rotates a constrained bone to match the rotation of its source objects. The constraint applies rotation about the shortest path to each source. The order the sources are specified does not affect the result.

## 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)

## SolveRotationConstraint(AnimationStream, RotationConstraintData, float)

Rotation constraint solver rotates a constrained bone to match the rotation of its source objects. The constraint applies rotation about the shortest path to each source. The order the sources are specified does not affect the result.

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

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The animation stream to apply the solver to.**** (\[RotationConstraintData]\(/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata)): The solver settings. See [Core.RotationConstraintData](/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata.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 the rotation with a normalized linear interpolation.

## SolveRotationConstraint(AnimationStream, RotationConstraintData, quaternion, quaternion, float)

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

```csharp
public static void SolveRotationConstraint(ref AnimationStream stream, in Core.RotationConstraintData data, quaternion sourceRotation, quaternion sourceOffset, float weight)
```

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The animation stream to apply the solver to.**** (\[RotationConstraintData]\(/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata)): The solver settings. The method uses only [Core.RotationConstraintData.Index](/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata/index.md), [Core.RotationConstraintData.LocalAxesMask](/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata/localaxesmask.md), and [Core.RotationConstraintData.LocalOffset](/engine/7000.0/script-reference/unity/animations/core/rotationconstraintdata/localoffset.md), and ignores the source arrays.**** (\[quaternion]\(/engine/7000.0/script-reference/unity/mathematics/quaternion)): The source rotation, in character space. To follow a world-space target, convert it first with `math.mul(math.inverse(characterToWorld.rot), worldRotation)`.**** (\[quaternion]\(/engine/7000.0/script-reference/unity/mathematics/quaternion)): The rotation offset in the local space of the source. The solver multiplies it after `sourceRotation`.**** (\[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 the rotation with a normalized linear interpolation.

### Remarks

Use this overload when the constraint has one source. It gives the same result as [Core.SolveRotationConstraint](/engine/7000.0/script-reference/unity/animations/core/solverotationconstraint.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);
}
```
