How do I make two movement types?

cjswanson1355

New member
How do I have two different movement types with different physics? I have a basic walk setup, but I also want a dive function where gravity gets applied and the character moves fast but has some limited control. But I can only find functionality for a single global set of physics.

I see the settings under UltimateCharacterLocomotion...but how do i have different settings depending on if my character is sliding vs walking?
 

Attachments

  • Capture.PNG
    Capture.PNG
    67.4 KB · Views: 5
This is exactly the kind of thing the state system is for - you could have a different state for each movement type, then a preset for each one to adjust the various motor/physics settings as needed.

To actually activate the state, you'd need a simple script to listen for when the movement type is changed and activate the appropriate state. You can use the OnCharacterChangeMovementType event for this, as described on this page.

This is an untested basic mockup, but to give you a general idea:

C#:
using UnityEngine;
using Opsive.Shared.Events;
using Opsive.Shared.StateSystem;
using Opsive.UltimateCharacterController.Character.MovementTypes;

public class MovementTypeListener : MonoBehaviour
{
    void OnEnable() {
        EventHandler.RegisterEvent<MovementType>("OnCharacterChangeMovementType", OnCharacterChangeMovementType);
    }
    
    void OnCharacterChangeMovementType(MovementType movementType) {
        if (movementType is MovementTypeA) {
            StateManager.SetState(characterGameObject, "StateA", true);
            StateManager.SetState(characterGameObject, "StateB", false);
        } else if (movementType is MovementTypeB) {
            StateManager.SetState(characterGameObject, "StateB", true);
            StateManager.SetState(characterGameObject, "StateA", false);
        }
    }
    
    void OnDestroy() {
        EventHandler.UnregisterEvent<MovementType>("OnCharacterChangeMovementType", OnCharacterChangeMovementType);
    }
}
 
A big part of learning programming, Unity, etc. is going down the wrong path! It's a great way to learn.
 
Top