Hello Invector community! Keeping this one alive for the latest Invector release (2.6.3 as of the writing of this). Please note I am not a guru pertaining to this library, if anyone sees anything incorrect below, please comment.
---
To start off, as above modify vThirdPersonMotor.cs to add the following member variables at the end of the "Jump" section
[Tooltip("Increase number to enable multiple jumps on your character")]
[Range (1, 10)]
public int MultiJump = 1;
[HideInInspector]
public int currentMultiJump = 0;
As explained above "MultiJump" is the variable that you will set in the Unity Inspector to specify the number of jumps the player can perform before landing.
In this same file, edit the ControlJumpBehaviour, method to look like so:
protected virtual void ControlJumpBehaviour()
{
if (!isJumping)
{
if(isGrounded) currentMultiJump = 0;
return;
}
// The rest of the method is the same as before
This method is called in FixedUpdate (every single game loop iteration), so it's a good place to check if we are grounded and reset the currentMultiJump counter.
---
Next, modify vThirdPersonInput.cs, changing the JumpConditions function to look like so.
protected virtual bool JumpConditions()
{
return !cc.inJumpStarted && !cc.customAction && !cc.isCrouching && cc.currentStamina >= cc.jumpStamina && !cc.isRolling &&
(cc.currentMultiJump < cc.MultiJump) && (!cc.isGrounded || cc.GroundAngle() < cc.slopeLimit);
}
The changes were made here:
- The "!isJumping" condition was removed so that even if the character is currently jumping they can jump again
- "currentMultiJump < MultiJump" is checked to see if the player has reached their jump limit. We'll set the "currentMultiJump" variable below.
- The grounded and ground angle conditions were changed to so: "!isGrounded || GroundAngle < slopeLimit", which ensures that if the user is not grounded, the ground slope constraint is not enforced
---
Next we need to edit vThirdPersonController.cs. Specifically, change the Jump and DelayToJump methods like so:
public virtual void Jump(bool consumeStamina = false)
{
// trigger jump behaviour
jumpCounter += jumpTimer;
OnJump.Invoke();
// trigger jump animations
if(currentMultiJump > 0){
isJumping = true;
++currentMultiJump;
animator.CrossFadeInFixedTime("JumpingUp", .2f);
}
else if (input.sqrMagnitude < 0.1f)
{
StartCoroutine(DelayToJump());
animator.CrossFadeInFixedTime("Jump", 0.1f);
}
else
{
isJumping = true;
++currentMultiJump;
animator.CrossFadeInFixedTime("JumpMove", .2f);
}
// reduce stamina
if (consumeStamina)
{
ReduceStamina(jumpStamina, false);
currentStaminaRecoveryDelay = 1f;
}
}
protected IEnumerator DelayToJump()
{
inJumpStarted = true;
yield return new WaitForSeconds(jumpStandingDelay);
isJumping = true;
++currentMultiJump;
inJumpStarted = false;
}
The changes here are the following:
- Incrementing the "currentMultiJump" counter
- Increment the jump timer instead of setting it (so as not to clear it during every multi-jump)
- Play a different Animation "Jump Up" during any jump after the first.
Of course with the above you'll need to add the "Jump Up" animation to the "Invector@Basic Locomation" animator. To do so:
- create a new jumping animation clip (or download one from Mixamo or such)
- Double click on the animator asset to edit it
- Double click on the "Airborne" sub-state machine and then the "Jump" sub-state machine
- Drag your animation clip into the animation
- Right click on it and "Create a Transition" to the "Exit" state
- In the popup menu, select the "Falling" state and you are done!
That should be all... hope it helps!