Crouch and Run Ability

MarkusKer

Member
Hello,

i was wondering if it is somehow possible to start running from the crouch state.
I was playing around with the order of the abilities and the state system but somehow was unable to find an suitable solution.
I want to be able to be in the running state and than start to crouch.
If i than press the run key i would like to stop crouching and start running.

Regards,
Markus
 
The HeightChange ability and the SpeedChange ability are both concurrent abilities so they can activate at the same time. Make sure the SpeedChange has a higher priority than the HeightChange ability. We don't have running crouch animations so you'll need to add your own to the animator controller.

In the next version I'll add an option to the HeightChange or SpeedChange ability to make it more straight forward so you know that they both can work together.
 
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.Events;

public class startrunning : MonoBehaviour
{
[Tooltip("The character that should start and stop the jump ability.")]
[SerializeField] protected GameObject m_Character;




/// <summary>
/// Starts and stops the jump ability.
/// </summary>
///



private void Update()
{
var m_PlayerInput = m_Character.GetComponent<PlayerInput>();
if (m_PlayerInput.GetButtonDown("Change Speeds"))
{
StartSprint();
}
}

public void StartSprint()
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
var jumpAbility = characterLocomotion.GetAbility<HeightChange>();
// var jump2Ability = characterLocomotion.GetAbility<HeightChange>();

Debug.Log("hello");
characterLocomotion.TryStopAbility(jumpAbility);

}
}
 
Top