|
Post by midgear on Oct 18, 2019 9:03:40 GMT
I have a game where the player can warp around like Nightcrawler from the x men, but right now the warp costs no stamina, and I would like it to cost some stamina. I think I need to be using the event's on the Generic Animation, but I don't know what event I need to be using. How can I do this? Image Reference:
|
|
|
Post by shadex on Oct 20, 2019 19:22:06 GMT
I have a game where the player can warp around like Nightcrawler from the x men, but right now the warp costs no stamina, and I would like it to cost some stamina. I think I need to be using the event's on the Generic Animation, but I don't know what event I need to be using. How can I do this? Image Reference: I found it most usefull to put it on the actual animation itself inside the behavior state machine. Here is some of my code you can use as a template to make your own
using System.Collections; using System.Collections.Generic; using UnityEngine; using Invector.vCharacterController; public class StaminaCostBehavior : StateMachineBehaviour {
/* * Place on any state. When the state is activated, it will reduce the stamina by StaminaReduction amount * Accumlative is an stamina drain over time. * Stamina Recovery Delay is how many seconds till stamina recovery kicks in. This only applies * to the current state. A roll, attack, jump, sprint or any stamina using action will reset to default * values. * PermanentChangeStaminaRecovery changes how fast stamina is recovered. This will permanently change * the value. Currently it doesn't store the default value. Use with care */ [Header("Damage")] [Tooltip("In percentage. 30 = 30%")] public float DamageBoost; private vThirdPersonController HeroBase;
[Header("Stamina")] [Tooltip("Reduces Stamina by X Amount")] public float StaminaReduction; [Tooltip("Stamina Cost Over Time")] public bool Accumlative; [Tooltip("Temp Delay till you recover stamina. Only for this State")] public float Stamina_Recovery_Delay; [Tooltip("Changes how fast Stamina is recovered. Lasts until overwritten")] public float PermanentChangeStaminaRecovery;
// public GameObject player;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { HeroBase = animator.GetComponentInChildren<vThirdPersonController>(); animator.SetFloat("DamageBoostPercent", DamageBoost); if (StaminaReduction != 0) { HeroBase.ReduceStamina(StaminaReduction, Accumlative); } if (Stamina_Recovery_Delay != 0) { HeroBase.currentStaminaRecoveryDelay = Stamina_Recovery_Delay; } if (PermanentChangeStaminaRecovery != 0) { HeroBase.staminaRecovery = PermanentChangeStaminaRecovery; } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //}
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //}
// OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here. //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} }
|
|
|
Post by midgear on Oct 22, 2019 15:27:52 GMT
That worked like a charm, the only problem now is how to get it so I can't use then Generic Animations when I have zero stamina?
|
|
|
Post by midgear on Oct 22, 2019 16:25:12 GMT
I found a dumb way to do it, but it gets the job done, I set up a Playmaker FSM to pull the stamina from the Player UI and send it to the Animator Controller as a float. When the player does the custom animation the Animator controller does a Stamina Greater then check.
If anyone has a better way of doing this I'm all ears.
|
|
|
Post by shadex on Oct 25, 2019 6:13:43 GMT
I found a dumb way to do it, but it gets the job done, I set up a Playmaker FSM to pull the stamina from the Player UI and send it to the Animator Controller as a float. When the player does the custom animation the Animator controller does a Stamina Greater then check. If anyone has a better way of doing this I'm all ears. Because stamina changes so much, simply putting it in update to pass stamina to the animator as a float is good enough. The best way i think would be using an event, which is most likely what you did in playmaker. I find it helpful to pass a lot of stats (variables) to the animator. Health, strength, weight, etc. It doesn't cost much CPU to do, and those parameters come in so handy in the animator. For instance being able to change walking animations based on health, or access do different attack's with strength.
|
|