Start Jump Ability - Long press & Force hold

Klin

Member
Hi,
I want the jump ability to start, after "Wait for long Press Release" but also have the "Force Hold" applied, as long as the button is being pressed down.

Basically combine the "Button Down Continious" and "Long Press - Wait for Long Press Release".

Could you maybe give me a hint on how to apply that?
Do I have to modify Ability.cs, modify it in jump.cs or maybe just missing a simple click in the inspector?

Thanks for helping out!
 
A quick way to do this would be to create a custom Jump ability (a class inheriting from Jump), set Force when the jump key is released based on how long it was held for, and manually start the ability (i.e. use Manual start type). It would look something like:

C#:
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.Shared.Input;
using UnityEngine;

public class MyCustomJump : Jump
{
    PlayerInput playerInput;
    float pressDownTime;
    
    public override void Awake() {
        base.Awake();
        
        playerInput = GetComponent<PlayerInput>();
        pressDownTime = 0;
    }
    
    public override void InactiveUpdate() { // InactiveUpdate gets called every frame when the ability is not active
        base.InactiveUpdate();
        
        if (playerInput.GetButtonDown("Jump")) {
            pressDownTime = Time.unscaledTime;
        }
        if (playerInput.GetButtonUp("Jump")) {
            float heldTime = Time.unscaledTime - pressDownTime;
            if (heldTime > 0) {
                m_Force = 0.2f + (0.2f * heldTime); // Adjust these values to change how the jump force scales based on input held time
                StartAbility();
            }
        }
    }
}
 
Top