Skip to main content
The Align Component handles melee combat and environmental interactions by snapping your character into the correct position and orientation relative to a target object — an enemy, a car, a door, or any interactive GameObject. Instead of attaching it to your character, you add the Align Component to the object your character will interact with. When the player triggers an interaction, the component validates the angle and distance, then the Motion Warping system drives the character to the precise aligned position.

Add to the Interaction Target

Attach the AlignComponent to the GameObject your character will interact with — for example, an enemy character, a vehicle, or an environmental prop. Do not add it to the player character itself.

Component Properties

float
required
The maximum allowed angular difference (in degrees) between the character’s approach direction and the target object’s forward axis. If the character approaches from outside this cone, the interaction is rejected. This prevents the player from triggering a front-facing attack animation while standing behind the target.
float
required
A yaw rotation offset applied to the Interaction Angle cone. Use this to rotate the valid interaction zone around the target object’s up axis — for example, to allow interactions from a slightly offset frontal arc rather than dead-ahead.
float
required
The maximum allowed distance between the character and the target object. If the character is farther away than this value when Interact is called, the interaction is rejected.
string
required
The name of the animation to play on the target object (the object the AlignComponent is attached to) during the interaction. For example, this could be a hit-reaction animation on an enemy, a door-opening animation, or a vehicle interaction. The character’s animation is controlled separately by the Motion Warping Asset.

How It Works

The most common pattern is to use Unity’s collision trigger system to track which interactable object the character is near, then call Interact when the player presses the appropriate button. Use OnTriggerEnter and OnTriggerExit on your character to store and clear a reference to the interaction target, then call the Interact method on the MotionWarping component and pass the target’s GameObject:
When Interact is called with the target GameObject, the system retrieves the AlignComponent attached to that object and validates the Distance and Interaction Angle checks. If both pass, the warp interaction begins and the character is driven from its current position to the aligned target position.
The _interactionTarget variable holds a reference to the GameObject that carries the AlignComponent — not the character. Make sure the collision trigger on your character overlaps with the collider on the target object so that OnTriggerEnter fires correctly.
You can also drive TryInteracting from an Animation State Machine transition, an Ability System task, or any other game-logic hook — the trigger/exit pattern above is simply the most straightforward approach.

Motion Warping Asset Requirements

The character moves from its current position to the aligned position relative to the target object in a single motion, so the Motion Warping Asset assigned to this interaction requires exactly one Warp Phase.
The single Warp Phase maps the character’s root motion from its current transform to the position and orientation dictated by the AlignComponent on the target object. Ensure your interaction animation’s root motion faces forward along the character’s local Z axis so the warped alignment is correct.