Move Towards

The Move Towards ability will move the character to a specified location. This is most useful in situations where the character must be in a precise location before another ability can start. As an example the Interact ability may require the ability to be positioned in front of a door before that door can be opened, or a Climb ability may require the character to be positioned in front of the ladder before the character can mount on that ladder.

If a pathfinding ability, such as the NavMeshAgent Movement ability, has been added then the Move Towards ability will use pathfinding to move towards the location.

The Move Towards ability works with the Move Towards Location component in order to determine the location that the character should move towards.

Setup

  1. Select the + button in the ability list under the “Abilities” foldout of the Ultimate Character Locomotion component.
  2. Add the Move Towards ability. The ability will be able to start no matter what position it is in within the ability list.
  3. On the Ultimate Character Locomotion component create a state which sets the Motor Rotation Speed to a larger value. In the demo scene the Motor Rotation Speed is set to 100.

API

The Move Towards ability can be started through script with the MoveTowardsLocation method. MoveTowardsLocation takes a Vector3 position and will move the character to that destination.

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);
    }
}

Inspected Fields

Input Multiplier

The multiplier to apply to the input vector. Allows the character to move towards the destination faster.

Inactive Timeout

The amount of time it takes that the character has to be stuck before teleporting the character to the start location.

Move Target Distance Timeout

Specifies the maximum distance that the target position can move before the ability stops.

Teleport on Early Stop

Should the character be teleported after the timeout or max moving distance has elapsed? If false the character will stop.

Disable Gameplay Input

Should the OnEnableGameplayInpt event be sent to disable the input when the ability is active?

Independent Move Towards Location

The location that the Move Towards ability should move towards if the ability is not started by another ability.