Restrict movement on a character

Haytam95

Active member
Hi!

I've been looking around for a simple way to make my character have the movement restricted, but still be able to interact with the environment. As I didn't found any proper way to make it work (Change motor acceleration still performs the movement animation and disable gamepad input prevents interaction and camera rotation), I've made this simple movement type to achieve this.

C#:
using Opsive.UltimateCharacterController.Character.MovementTypes;
using UnityEngine;

public class MovementRestricted : MovementType {
    public override bool FirstPersonPerspective => true;
    public override bool UseIndependentLook(bool characterLookDirection) => true;

    public override float GetDeltaYawRotation(float characterHorizontalMovement, float characterForwardMovement,
        float cameraHorizontalMovement, float cameraVerticalMovement) {
        return 0;
    }

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

}

Just add it as "Movement type" and change to it at runtime (or whenever you want!)

1612022772310.png


Here is the script that you should use to change the movement type at runtime:

m_CharacterLocomotion.SetMovementType(typeof(MovementRestricted));
 
I imagine you would just call,
m_CharacterLocomotion.SetMovementType(typeof(ThirdPersonAdventure));

If you wanted third person adventure
 
SetMovementType(typeof(Opsive.UltimateCharacterController.ThirdPersonController.Character.MovementTypes.TopDown));

I did it this way. Thank you very much for sharing what you have done!
 
Top