Player cannot stop Attacking enemy

I have followed the tutorials step by step for the character scripts and setup for having the character move both by mouse click then by holding down the mouse.

Then I go to click on the enemy. The character runs up, and starts to attack the enemy. But I have gone all the way through the course to where I am stopping the player from attacking with the stopAttack trigger. But even with getting everything down step by step. My character will always stay stuck in combat and will not leave.

Here is a link to the code I have for my scripts. I double checked the animator settings and they are all set correctly. I checked those from other questions and they should not be effecting this.

Link to my scripts: pastemyst | GameDev RPG Project Code Work

I really am lost here and I am not sure what I am missing.

I think the issue is in your ActionScheduler… I’ll post it here for reference:

        public void StartAction(IAction action)
        {
            if (currentAction == null) return; //because of this line currentAction will never be null
            if (currentAction != null)
            {
                currentAction.Cancel();
            }
            currentAction = action;
        }

So when StartAction is called, you’re checking to see that currentAction is null, and returning if it is… what this means is that at no point will currentAction ever not be null because this is where currentAction is set to an action.
We’re null checking again (but inverting it) for Cancel, and this is correct.
Removing that first line should solve your issue completely.

That solved my problem!! Thank you so much for the input! I will go back through the last few lessons and see where I had that added in my code to see what had me add that in the first place.

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

Privacy & Terms