Move Towards
Move Towards places and faces a character at a precise location before another ability begins. Use it when an interaction, climb, animation, or other action should start from a controlled position, or when gameplay code needs to send the character to a location without starting a follow-up ability.
Before you begin
- The character must have an Ultimate Character Locomotion component.
- For an arrival ability such as Interact, add one or more Move Towards Location components to the object that provides the interaction or action point.
- If the character should navigate around obstacles, set up NavMeshAgent Movement and a baked NavMesh.
- Ensure the character’s movement animations can cover the approach speed. With root motion enabled, the animation supplies the visible displacement.
Add Move Towards
- Select the character GameObject.
- In the Ultimate Character Locomotion component, expand Abilities.
- Select the plus button and add Move Towards.
- Keep Start Type set to Manual. Another ability or gameplay code starts Move Towards when a destination is available.
- Order the abilities from higher to lower in this sequence: pathfinding above Move Towards, then Move Towards above the ability it prepares. For example, place NavMeshAgent Movement above Move Towards and Move Towards above Interact. If Speed Change is also present, keep it above NavMeshAgent Movement.
- If the character turns too slowly during final alignment, create a state for Move Towards and increase Motor Rotation Speed while that state is active. The demo uses a value of
100. - Choose a destination source and configure the movement and stop settings described below.
Choose how to supply the destination
Move before another ability
An ability that requires exact placement supplies an array of Move Towards Location components. Move Towards chooses the closest location, travels to it, stops, and then starts the waiting ability. If the character already satisfies a location’s position and rotation thresholds, Move Towards does not need to start.
Place Move Towards above the waiting ability in the Abilities list. A waiting ability above Move Towards has higher priority and can cause unintended behavior.
Move to an independent location
Assign Independent Move Towards Location when Move Towards should use one particular component without a waiting ability. Start the ability manually through the locomotion system.
Gameplay code can instead call MoveTowardsLocation with a position or with a position and rotation. The position-only overload accepts any final facing direction. Both overloads create an independent location when one has not already been assigned and can update the destination while Move Towards is active.
Configure the destination
The Move Towards Location component defines where arrival is valid:
- Offset and Yaw Offset place and face the character relative to the location object’s Transform.
- Size creates an acceptable area instead of requiring one exact point. Distance adds positional tolerance.
- Angle controls the accepted facing range. Increase it when exact facing does not matter; reduce it when the following animation must begin from a specific orientation.
- Require Grounded prevents arrival until the character is grounded.
- Precision Start waits for movement and Animator transitions to settle before the waiting ability begins. Keep it enabled for tightly aligned interactions; disable it when an immediate handoff is more important than a settled pose.
- Movement Multiplier scales movement for this location without changing every Move Towards use on the character.
Use the location gizmo in the Scene view to confirm that the target point, valid area, and facing direction match the object the character will use.
Choose movement and rotation behavior
Input Multiplier scales the input Move Towards supplies. The final value also includes the selected location’s Movement Multiplier and any active Speed Change multiplier.
- Without a pathfinding ability, Move Towards supplies direct input toward the location, limits the final movement to avoid overshooting, and rotates toward the target using the character’s Motor Rotation Speed.
- With Pathfinding Movement above Move Towards, pathfinding handles the route to the target. Move Towards then checks the location’s final position and rotation requirements before completing the handoff.
- With root motion enabled, these input values select and drive movement animation, but the animation’s root motion determines the character’s visible displacement. Use an animation whose speed matches the intended approach.
Move Towards temporarily takes independent control of looking so it can complete the requested facing. That control is released when the ability stops.
Choose what happens when movement cannot finish
- Inactive Timeout is how long the character may make no positional or rotational progress before Move Towards stops early. The default is
1second. - Moving Target Distance Timeout is how far the target may move from its starting position before Move Towards stops early. Its default is effectively unlimited.
- Teleport On Early Stop is enabled by default. When enabled, an early stop places the character at the target and starts the waiting ability when one is pending. Disable it when teleporting would be visible or when a blocked approach should cancel the action instead.
- Disable Gameplay Input sends the gameplay-input event while Move Towards is active, preventing player input from competing with the automatic approach. Input is restored when the ability stops.
How Move Towards runs
When another ability requests movement, Move Towards selects the closest supplied location. For an independent request, it uses the assigned or script-created location. The ability does not start when the character is already inside the allowed position and rotation thresholds.
If a Pathfinding Movement ability exists above Move Towards, it receives the destination and guides the character along the NavMesh. Move Towards otherwise supplies direct input. Near the destination, it checks the position, grounded requirement, and facing angle, then waits for the precision-start condition when enabled.
After arrival, Move Towards stops its active pathfinding ability, restores gameplay input and normal look control, and starts the waiting ability. A stalled character or a target that exceeds the configured movement limit follows Teleport On Early Stop instead.
Verify in Play Mode
- Trigger the waiting ability while the character is outside the Move Towards Location’s valid area.
- Confirm (Active) appears beside Move Towards in the Ultimate Character Locomotion Inspector.
- If NavMeshAgent Movement is configured above it, confirm the character follows the NavMesh toward the destination. Without pathfinding, confirm the character approaches directly.
- Confirm the character reaches the location’s allowed position, becomes grounded when required, and turns inside the configured Angle.
- With Precision Start enabled, confirm the movement pose settles before the waiting ability starts.
- For a root-motion character, confirm the intended approach animation plays and its motion reaches the location without sliding.
- Block the route long enough to exceed Inactive Timeout and verify that the result matches Teleport On Early Stop.
- Move the target beyond Moving Target Distance Timeout and confirm the same early-stop policy is applied.
Troubleshoot Move Towards
- The waiting ability starts before the character is aligned: check that it returns the intended Move Towards Location, place Move Towards above that ability, enable Precision Start, and reduce the location’s Distance or Angle as needed.
- A path is never used: confirm the NavMesh is baked, the character and destination are on it, and NavMeshAgent Movement is above Move Towards in the list.
- The character reaches the point but turns too slowly: check the Move Towards state and increase Motor Rotation Speed while it is active.
- The character overshoots or slides around the point: check that the movement animation matches the requested input, reduce Input Multiplier or the location’s Movement Multiplier, and increase Distance slightly when an exact point is unnecessary.
- The character stops after one second: it is not producing position or rotation progress. Check collision, the path, movement animation, and rotation speed, then increase Inactive Timeout only if the approach legitimately pauses.
- The character unexpectedly teleports: disable Teleport On Early Stop or correct the obstruction, movement timeout, or moving-target limit that caused the early stop.
- Player input changes the approach: enable Disable Gameplay Input when the automatic movement should have exclusive control.
- A root-motion character does not move faster after increasing Input Multiplier: use a faster root-motion animation at the resulting movement input; the multiplier does not change the distance embedded in the clip.
Related topics
- Move Towards Location defines the valid arrival position and rotation.
- NavMeshAgent Movement provides obstacle-aware pathfinding and must remain above Move Towards.
- Speed Change can scale the approach input and must remain above NavMeshAgent Movement when both are present.
- Interact is a common example of an ability that waits for precise placement.
- Abilities explains list priority, manual activation, and the shared ability lifecycle.
- State System explains temporary property changes such as a faster Motor Rotation Speed.
Developer reference
The Move Towards ability can be started through script with the MoveTowardsLocation method. This example supplies a position; the position-only overload accepts any final rotation.
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
public class MyObject : MonoBehaviour
{
[Tooltip("The character that should move towards the destination.")]
[SerializeField] protected GameObject m_Character;
[Tooltip("The destination that the character should move towards.")]
[SerializeField] protected Vector3 m_Destination;
/// <summary>
/// Starts moving to the destination.
/// </summary>
private void Start()
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
characterLocomotion.MoveTowardsAbility.MoveTowardsLocation(m_Destination);
}
}
The current runtime surface includes:
- MoveTowardsLocation(Vector3): starts or updates movement to a position and accepts any final rotation.
- MoveTowardsLocation(Vector3, Quaternion): starts or updates movement to a position and rotation.
- StartMoving(MoveTowardsLocation[], Ability): chooses the closest location and returns whether Move Towards started for the waiting ability.
- StartLocation and OnArriveAbility: expose the selected location and waiting ability while the workflow is active.
- InputMultiplier, InactiveTimeout, MovingTargetDistanceTimeout, TeleportOnEarlyStop, DisableGameplayInput, and IndependentMoveTowardsLocation: expose the Inspector configuration.
- OnEnableGameplayInput: is sent with
falseand thentruewhen Disable Gameplay Input is enabled. - OnCharacterForceIndependentLook: is sent while Move Towards owns final facing and again when that control is released.
- OnCharacterAbilityActive: lets Move Towards track an active Speed Change and include its multiplier in the generated input.