|
Post by sickscore on Feb 16, 2017 8:38:13 GMT
DOUBLE JUMP / MULTI JUMPS BECAUSE GRAVITY IS NOT ALWAYS THE LAW! :D
Hey guys,
as requested in this thread, here is a working solution for double/multiple jumps. The amount of possible jumps can be controlled by a slider in the inspector.
Cheers, sickscore vThirdPersonMotor.cs// insert at the end of "Jump Options"[Tooltip("Increase number to enable multiple jumps on your character")] [Range (1, 10)] public int MultiJump = 1; [HideInInspector] public int currentMultiJump; vThirdPersonController.cs// replace/modify Jump functionpublic virtual void Jump() { if (animator.IsInTransition (0)) return;
// know if has enough stamina to make this action bool staminaConditions = currentStamina > jumpStamina;
// conditions to do this action bool jumpConditions = !isCrouching && !actions && staminaConditions;
// check if multi jump is possible if (MultiJump > 1) { // reset multi jump counter if (isGrounded) currentMultiJump = 0;
// check if we reached the max jump value jumpConditions = jumpConditions && currentMultiJump < MultiJump;
// increase multi jump counter if (jumpConditions) { currentMultiJump++; // zero out velocity before next jump Vector3 jumpVelocity = _rigidbody.velocity; jumpVelocity.y = 0f; _rigidbody.velocity = jumpVelocity; } } else { // single jump conditions jumpConditions = jumpConditions && isGrounded && !isJumping; }
// return if jumpConditions is false if (!jumpConditions) return;
// trigger jump behaviour jumpCounter = jumpTimer; isJumping = true;
// trigger jump animations if (speed < 0.1f) animator.CrossFadeInFixedTime ("Jump", 0.1f); else animator.CrossFadeInFixedTime ("JumpMove", 0.05f); // reduce stamina ReduceStamina (jumpStamina, false); currentStaminaRecoveryDelay = 1f; }
|
|
|
Post by shadex on Feb 17, 2017 17:25:34 GMT
Oh this is awesome! Thank you much. Look forward to trying it out!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 17, 2017 17:33:52 GMT
Thank you Dude!!!!!! Also can't wait to try out :D
|
|
|
Post by codeassembler on Feb 18, 2017 6:07:15 GMT
This one will be cool to try out! Thanks!!!
*Edit* - Man it works really nice!! Super fun! I just edited the jumpConditions line to adjust the jumps index since somehow it was adding an extra jump, then it worked flawless! Lot of Thanks since your approach is super clean and in sync with the existent logic flow!!!
Here is the small edit:
// check if we reached the max jump value
jumpConditions = jumpConditions && (currentMultiJump <= MultiJump - 1);
- Luis
|
|
|
Post by sickscore on Feb 18, 2017 18:00:05 GMT
This one will be cool to try out! Thanks!!! *Edit* - Man it works really nice!! Super fun! I just edited the jumpConditions line to adjust the jumps index since somehow it was adding an extra jump, then it worked flawless! Lot of Thanks since your approach is super clean and in sync with the existent logic flow!!! Here is the small edit: // check if we reached the max jump value jumpConditions = jumpConditions && (currentMultiJump <= MultiJump - 1); - Luis Thx, I updated the code above. Btw, u can just write "<" instead of "-1" ;-)
|
|
|
Post by codeassembler on Feb 19, 2017 0:18:44 GMT
You are absolutely right! Too use to quick hacking I guess XD
|
|
|
Post by snackzilla on Apr 4, 2017 0:47:34 GMT
This one is great! Easy to implement and well commented. sickscore If I wanted to make the second jump higher(an independent value from jump), where at in the code would I tell it to apply the extra velocity?
|
|
|
Post by snackzilla on Apr 4, 2017 12:22:02 GMT
This one is great! Easy to implement and well commented. sickscore If I wanted to make the second jump higher(an independent value from jump), where at in the code would I tell it to apply the extra velocity? I actually just came across your Flying addon as well, so I'm not sure what would be better. I'm trying to create an assisted DoubleJump. That is, the player will jump once, and if jump is pressed again mid-jump, he will jump higher depending on my own variable (Jetpack Fuel). You can see where I'm going with this. Jump once -> Jetpack Jump with it's own force and "stamina"(fuel). Really, I can figure out the the stamina stuff myself. Just need help figuring out how to make the second jump have it's own velocity. Forgive me, english is not my first language. I hope I am being clear.
|
|
|
Post by snackzilla on Apr 19, 2017 0:12:25 GMT
So simple a solution! That works wonders! I wonder if it could be modified to accept a second "Jump" animation rather than just replaying the first one?
|
|
|
Post by tharindu on Apr 21, 2017 2:30:16 GMT
So simple a solution! That works wonders! I wonder if it could be modified to accept a second "Jump" animation rather than just replaying the first one? My belief is you can, like you do combat animations. But you would need to possibly add a counter to the animator and probably make a few changes there. May be even work a bit on the animation state behavior. So I'd say to do it outside the addon if it fits your purpose
|
|
|
Post by gembit on Nov 2, 2017 4:06:01 GMT
I have been trying to work out how to add a glider similar to in Zelda: Breath Of The Wild to my project. If you haven't played the game, the glider functions just like you'd expect, you jump off a high mountain and press a button to bring it out and then glide slowly to the ground.
Do you think this would be right addon to use to attempt this feature? I've never attempted to customise the controller to this extent before but let me know what you make of my plan lol...
My current work around plan would be to use this addon, create an animation of my character bringing out the glider, and then use that animation for my second jump. The next step would be affecting gravity so my character wouldn't fall to the ground but rather float. This is the part where I am kind of stuck. Any suggestions on how I might go about setting this up would be greatly appreciated!
|
|
|
Post by G 4 greatness on Dec 16, 2017 13:57:04 GMT
hie guys
i did everything as above , no errors showing on the console but the problem is .... character does not multi_jump at all... what could be the problem
|
|
|
Post by tshellberg on Jan 2, 2018 19:29:30 GMT
So simple a solution! That works wonders! I wonder if it could be modified to accept a second "Jump" animation rather than just replaying the first one? Anyone else set something like this up? I thought it would be super easy to do but it's not working. I should only need to create a new animation within the 'Jump' state(let's call it Jump Attack), create transitions from 'Jump' and 'JumpMove' and set the conditions(when performing a "jump attack" set a trigger in the animator). I can easily set the trigger(I can see in the animator parameters section this works) but there are no actual transitions inside of the Jump state. Here's what I really don't understand about many of these animation controllers: I don't see their transitions actually happening in the animator. Normally when I'm testing animations the window will visually show which states are triggered and show the transitions but this doesn't happen in this case. Assuming that I create a transition without any conditions from "JumpMove" or "Jump" to another motion, shouldn't it play automatically every time I jump? Is something else taking over the animator and setting a new state? It's hard to know because I can't visually see the transitions or current state. Screencast of animator when testing: www.vidmeup.com/vid/5a4bdd4417969/720x428
|
|
|
Post by newbie on May 19, 2018 13:55:04 GMT
I can't Wait for Wall Run
|
|
|
Post by Strider on Jul 11, 2018 4:32:49 GMT
Any news on this script? want to implement it again but is not working :(
|
|