At a lost on three things in the RPG

Hello, I don’t know what is wrong, there are three things at the moment.

#1 I have a Special Move ability that right now does not call any damage but looks like the Animation is causing it. When I use the same Animation that I use for Action Items it doesn’t seem to cause damage.

#2 At one point the cooldown for the Special Move worked, but now I don’t know if adding the Animation and other stuff I missed placed it in the script, can’t use when out of Spirit works tho.

#3 With the wolfs the Brown one has the Attack Animation from the asset that came with it, but it causes no damage. The Gray wolf has the default Animation for an attack that the humanoids have and it causes damage. Don’t know if its the Animation or I have to code something special for it.

the code for #1

public class Spirit : MonoBehaviour, ISaveable
    {
        
        [SerializeField] float regenSpiritPercent = 50;
        [SerializeField] float coolDown = 5;
        [SerializeField] float SpiritCost = 10;
        [SerializeField] float buffEffectTime = 5;
        [SerializeField] float bonuesEffectAmount = 5;
        [SerializeField] GameObject spiriteffect = null;

        LazyValue<float> SpiritPoints;
        
        

        // for items that refill Spirit
        public void GainSpirit(float ISpiritAmount)
        {
            SpiritPoints.value = Mathf.Min(SpiritPoints.value + ISpiritAmount, GetMaxSpiritPoints());
            GainSpiritEffect();
        }

        private void GainSpiritEffect()
        {
            Instantiate(spiriteffect, transform);
        }
        private void Awake()
        {
            SpiritPoints = new LazyValue<float>(GetInitialSpirit);
        }
        private void Start()
        {

            SpiritPoints.ForceInit();

        }

        // for Special Moves

        private void Update()
        {
            coolDown -= Time.deltaTime;
            KeySpecialMove();
        }

        private void KeySpecialMove()
        {

            if (Input.GetKeyDown(KeyCode.Space) && SpiritPoints.value >= SpiritCost)
            {
                activeAblility();
                SpecialMoveAimation();
            }

        }

        private void activeAblility()
        {
            if (coolDown > 0) return;
            
            ReduceSpirit();
            UseAbility();
            StartCoolDown();
        }

        private void SpecialMoveAimation()
        {
            GetComponent<Animator>().SetTrigger("Special Move");
            GetComponent<Animator>().ResetTrigger("Attack");
        }

        private void ReduceSpirit()
        {
            print("lost SP");
            SpiritPoints.value = Mathf.Max(SpiritPoints.value - SpiritCost, 0);
        }
        // for each type of element ability
        protected virtual void UseAbility()
        {
            print("damage");
            
        }

        public void StartCoolDown()
        {
            coolDown = 0;
            GetComponent<Animator>().ResetTrigger("Special Move");
            print("CoolDown");
        }

That’s a lot of questions at once…
We’ll start with the last one… the wolf attacks… the reason the human attack is working (thought not actually animating the wolf) is that it contains an event “Hit”. You’ll need to add a Hit event in the Wolf’s animation.

My guess is that your Special animation also has a “Hit” event. You might want to copy the Special animation and remove that event.

Your cooldown is based on subtracting Time.deltaTime and not using the ability if cooldown is > 0, but StartCoolDown() sets coolDown to 0… try setting it to a positive number.

Thanks, the animations were Read Only so i got stuck on what to do, didn’t think i could duplicate the animations so that solved both and the cooldown works now. Sorry for the three questions at once, thanks again.

Don’t worry too much. It is easier, though, to tackle one problem at a time. In this case two of the problems were directly related with similar answers.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms