# AimConstraint

> Constrains the orientation of a GameObject based on the position of one or more sources.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Animations](/engine/6000.5/script-reference/unityengine/animations.md)
* **Assembly:** UnityEngine.AnimationModule
* **Inherits from:** [Behaviour](/engine/6000.5/script-reference/unityengine/behaviour.md)
* **Implements:** [IConstraint](/engine/6000.5/script-reference/unityengine/animations/iconstraint.md)

```csharp
[RequireComponent(typeof(Transform))]
public sealed class AimConstraint : Behaviour, IConstraint
```

## Remarks

Use this constraint to aim a GameObject towards one or more sources. For example, when you want to aim a turret towards many targets. You can also adjust the weight of each source to influence whether the constrained GameObject aims more towards one source over another source.

Make sure you use `AimConstraint` properties to align the orientation of the constraint. Otherwise, the constrained GameObject might aim in the wrong direction.

Refer to [Aim Constraint Component](/engine/6000.5/manual/working-with-gameobjects/unity-components/constraint-components/class-aim-constraint.md) for more details.

Additional Resources: [ConstraintSource](/engine/6000.5/script-reference/unityengine/animations/constraintsource.md), [LookAtConstraint](/engine/6000.5/script-reference/unityengine/animations/lookatconstraint.md), [ParentConstraint](/engine/6000.5/script-reference/unityengine/animations/parentconstraint.md).

## Examples

```csharp
// This example uses an AimConstraint to aim a GameObject towards two sources.
// The first source has a greater influence than the second source based on their assigned weight.

using UnityEngine;
using UnityEngine.Animations;

public class AimConstraintExample : MonoBehaviour
{
    public Transform sourceA;
    public Transform sourceB;
    private AimConstraint m_AimConstraint;

    void Start()
    {
        m_AimConstraint = gameObject.AddComponent<AimConstraint>();

        ConstraintSource source1 = new ConstraintSource { sourceTransform = sourceA, weight = 0.7f };
        ConstraintSource source2 = new ConstraintSource { sourceTransform = sourceB, weight = 0.3f };

        m_AimConstraint.AddSource(source1);
        m_AimConstraint.AddSource(source2);

        m_AimConstraint.constraintActive = true;
    }
}
```

## Properties

| Property                                                                                                     | Description                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [aimVector](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/aimvector.md)               | The axis towards which the constrained object orients.                                                                                                                                                                                                                                                                                                                         |
| [constraintActive](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/constraintactive.md) | Activates or deactivates the constraint.                                                                                                                                                                                                                                                                                                                                       |
| [locked](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/locked.md)                     | Locks the offset and rotation at rest.                                                                                                                                                                                                                                                                                                                                         |
| [rotationAtRest](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/rotationatrest.md)     | The rotation used when the sources have a total weight of 0.                                                                                                                                                                                                                                                                                                                   |
| [rotationAxis](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/rotationaxis.md)         | The axes affected by the AimConstraint.                                                                                                                                                                                                                                                                                                                                        |
| [rotationOffset](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/rotationoffset.md)     | Represents an offset from the constrained orientation.                                                                                                                                                                                                                                                                                                                         |
| [sourceCount](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/sourcecount.md)           | The number of sources set on the component (read-only).                                                                                                                                                                                                                                                                                                                        |
| [upVector](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/upvector.md)                 | The up vector.                                                                                                                                                                                                                                                                                                                                                                 |
| [weight](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/weight.md)                     | The weight of the constraint component.                                                                                                                                                                                                                                                                                                                                        |
| [worldUpObject](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worldupobject.md)       | The world up object, used to calculate the world up vector when the world up Type is [AimConstraint.WorldUpType.ObjectUp](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype/objectup.md) or [AimConstraint.WorldUpType.ObjectRotationUp](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype/objectrotationup.md). |
| [worldUpType](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype-1.md)         | The type of the world up vector.                                                                                                                                                                                                                                                                                                                                               |
| [worldUpVector](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worldupvector.md)       | The world up Vector used when the world up type is [AimConstraint.WorldUpType.Vector](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype/vector.md) or [AimConstraint.WorldUpType.ObjectRotationUp](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype/objectrotationup.md).                                       |

## Methods

| Method                                                                                               | Description                                |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [AddSource](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/addsource.md)       | Adds a constraint source.                  |
| [GetSource](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/getsource.md)       | Gets a constraint source by index.         |
| [GetSources](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/getsources.md)     | Gets the list of sources.                  |
| [RemoveSource](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/removesource.md) | Removes a source from the component.       |
| [SetSource](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/setsource.md)       | Sets a source at a specified index.        |
| [SetSources](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/setsources.md)     | Sets the list of sources on the component. |

## Enums

| Enum                                                                                                             | Description                                                              |
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [AimConstraint.WorldUpType](/engine/6000.5/script-reference/unityengine/animations/aimconstraint/worlduptype.md) | Specifies how the world up vector used by the aim constraint is defined. |

## Inheritance

**Inherited Members:**

* [Behaviour.enabled](/engine/6000.5/script-reference/unityengine/behaviour/enabled.md)
* [Behaviour.isActiveAndEnabled](/engine/6000.5/script-reference/unityengine/behaviour/isactiveandenabled.md)
* [Component.GetComponent(Type)](/engine/6000.5/script-reference/unityengine/component/getcomponent.md#getcomponent\(type\))
* [Component.GetComponent\<T>()](/engine/6000.5/script-reference/unityengine/component/getcomponent.md)
* [Component.TryGetComponent(Type, Component)](/engine/6000.5/script-reference/unityengine/component/trygetcomponent.md)
* [Component.TryGetComponent\<T>(T)](/engine/6000.5/script-reference/unityengine/component/trygetcomponent.md)
* [Component.GetComponent(string)](/engine/6000.5/script-reference/unityengine/component/getcomponent.md#getcomponent\(string\))
* [Component.GetComponentInChildren(Type, bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentinchildren.md#getcomponentinchildren\(type-bool\))
* [Component.GetComponentInChildren(Type)](/engine/6000.5/script-reference/unityengine/component/getcomponentinchildren.md#getcomponentinchildren\(type\))
* [Component.GetComponentInChildren\<T>(bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentinchildren.md)
* [Component.GetComponentsInChildren(Type, bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinchildren.md)
* [Component.GetComponentsInChildren\<T>(bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinchildren.md#getcomponentsinchildrent\(bool\))
* [Component.GetComponentsInChildren\<T>(bool, List\<T>)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinchildren.md)
* [Component.GetComponentsInChildren\<T>()](/engine/6000.5/script-reference/unityengine/component/getcomponentsinchildren.md#getcomponentsinchildrent\(\))
* [Component.GetComponentsInChildren\<T>(List\<T>)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinchildren.md)
* [Component.GetComponentInParent(Type, bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentinparent.md#getcomponentinparent\(type-bool\))
* [Component.GetComponentInParent(Type)](/engine/6000.5/script-reference/unityengine/component/getcomponentinparent.md#getcomponentinparent\(type\))
* [Component.GetComponentInParent\<T>(bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentinparent.md#getcomponentinparentt\(bool\))
* [Component.GetComponentInParent\<T>()](/engine/6000.5/script-reference/unityengine/component/getcomponentinparent.md#getcomponentinparentt\(\))
* [Component.GetComponentsInParent(Type, bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinparent.md)
* [Component.GetComponentsInParent\<T>(bool)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinparent.md#getcomponentsinparentt\(bool\))
* [Component.GetComponentsInParent\<T>(bool, List\<T>)](/engine/6000.5/script-reference/unityengine/component/getcomponentsinparent.md)
* [Component.GetComponentsInParent\<T>()](/engine/6000.5/script-reference/unityengine/component/getcomponentsinparent.md#getcomponentsinparentt\(\))
* [Component.GetComponents(Type)](/engine/6000.5/script-reference/unityengine/component/getcomponents.md#getcomponents\(type\))
* [Component.GetComponents(Type, List\<Component>)](/engine/6000.5/script-reference/unityengine/component/getcomponents.md#getcomponents\(type-listcomponent\))
* [Component.GetComponents\<T>(List\<T>)](/engine/6000.5/script-reference/unityengine/component/getcomponents.md)
* [Component.GetComponents\<T>()](/engine/6000.5/script-reference/unityengine/component/getcomponents.md#getcomponentst\(\))
* [Component.GetComponentIndex()](/engine/6000.5/script-reference/unityengine/component/getcomponentindex.md)
* [Component.CompareTag(string)](/engine/6000.5/script-reference/unityengine/component/comparetag.md#comparetag\(string\))
* [Component.CompareTag(TagHandle)](/engine/6000.5/script-reference/unityengine/component/comparetag.md#comparetag\(taghandle\))
* [Component.SendMessageUpwards(string, Object, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/sendmessageupwards.md#sendmessageupwards\(string-object-sendmessageoptions\))
* [Component.SendMessageUpwards(string, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/sendmessageupwards.md#sendmessageupwards\(string-sendmessageoptions\))
* [Component.SendMessage(string, Object)](/engine/6000.5/script-reference/unityengine/component/sendmessage.md#sendmessage\(string-object\))
* [Component.SendMessage(string)](/engine/6000.5/script-reference/unityengine/component/sendmessage.md#sendmessage\(string\))
* [Component.SendMessage(string, Object, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/sendmessage.md#sendmessage\(string-object-sendmessageoptions\))
* [Component.SendMessage(string, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/sendmessage.md#sendmessage\(string-sendmessageoptions\))
* [Component.BroadcastMessage(string, Object, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/broadcastmessage.md#broadcastmessage\(string-object-sendmessageoptions\))
* [Component.BroadcastMessage(string, SendMessageOptions)](/engine/6000.5/script-reference/unityengine/component/broadcastmessage.md#broadcastmessage\(string-sendmessageoptions\))
* [Component.transform](/engine/6000.5/script-reference/unityengine/component/transform.md)
* [Component.transformHandle](/engine/6000.5/script-reference/unityengine/component/transformhandle.md)
* [Component.gameObject](/engine/6000.5/script-reference/unityengine/component/gameobject.md)
* [Component.tag](/engine/6000.5/script-reference/unityengine/component/tag.md)
* [Object.GetEntityId()](/engine/6000.5/script-reference/unityengine/object/getentityid.md)
* [Object.GetHashCode()](/engine/6000.5/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.5/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.5/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type\))
* [Object.FindObjectsByType(Type, FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.5/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindAnyObjectByType\<T>()](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindObjectsByType\<T>()](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.5/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.5/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.5/script-reference/unityengine/object/hideflags.md)

### Operators

| Operator                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [operator ==](/engine/6000.5/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.5/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.5/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
