Movement Types define the target rotation of the character as well as what horizontal and forward inputs should be passed to the character. It is then up to the character controller to act on this target rotation and input vector to actually move the character.  Just because a value is passed to the character controller doesn’t mean the controller will act on it. For example, if the movement type says the character should move forward but there is a wall in front of the character then the character will not move forward.

Create New Movement Types

In most cases you don’t need to create a new Movement Type but if you do it’s a fairly easy process. New Movement Types can be created by inheriting the MovementType class and implementing two methods:

/// <summary>
/// Returns the target rotation of the character.
/// </summary>
/// <param name="characterHorizontalMovement">The character's horizontal movement.</param>
/// <param name="characterForwardMovement">The character's forward movement.</param>
/// <param name="cameraHorizontalMovement">The camera's horizontal movement.</param>
/// <param name="cameraVerticalMovement">The camera's vertical movement.</param>
/// <returns>The target rotation of the character.</returns>
Quaternion GetRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)

/// <summary>
/// Gets the controller's input vector relative to the movement type.
/// </summary>
/// <param name="inputVector">The current input vector.</param>
/// <returns>The updated input vector.</returns>
Vector2 GetInputVector(Vector2 inputVector)
GetRotation

The GetRotation method returns the target rotation of the character. This rotation can depend on the camera’s rotation or it can be completely independent of the camera.

GetInputVector

Returns the vector that will be used to actually move the character. The input vector is a Vector2 with the x value representing the horizontal movement and the y value representing forward movement.  A lot of Movement Types just return the inputted vector but in some cases (such as Top Down or 2.5D the input vector should be adjusted based on the camera’s rotation.

Example

The following Movement Type is an example of a complete movement type that prevents the character from rotating and also does not modify the input vector. This means when the character moves they will move relative to the character’s rotation.

using Opsive.UltimateCharacterController.Character.MovementTypes;

public class MyMovementType : MovementType
{
    public override Quaternion GetRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)
    {
        return m_Transform.rotation;
    }

    public override Vector2 GetInputVector(Vector2 inputVector)
    {
        return inputVector;
    }
}