Auto Attack cancel

IDK if I missed it, but abilities cancel our auto attacks. Do we fix this in the course or is it something I should debug on my own?

Like I use an ability, and the auto attack just stops.

I just rewatched “cancelling abilities” and it seems as though this is intended.

I am trying to figure this out on my own, but what I want to do is store the previous action in a variable called “previousAction” in the action scheduler, and have a function called “ResumePreviousAction”.

What I have is, when you cancel the current action, you set the previousAction to currentAction, then StartAction(null)

Then, in ResumePreviousAction, you set StartAction to previous action, then set previousAciton to null.

Where in Ability would I want to call ResumePreviousAction?

There’s also an empty function in Ability called “effect Finished”

Do we use that at all?

I skipped ahead and checked out the “auto attack” portion of the last seciton in shops & abilities, and it seems like that might fix my issue that I’m having. So I’m gonna shelve this until I actually get there :stuck_out_tongue:

We don’t “fix” it directly, and yes, there is definitely a “Let’s stop Auto Attack” to the Abilities.

In the final polish section, Sam presents a way to engage auto attack whenever you’re attacked, so run the ability (I actually recommend setting Time.timescale to 0 for this, then back to 1 when the Effects begin or the ability is cancelled), and then the character will resume auto attack when the baddy mc badguys hit him next .

Hopefully not too off topic but I am curious about the EffectFinished() method as well. What is the purpose of that?

This is a good place for cleanup code. For example, you could Destroy() the effect prefab, play a sound, etc. Sam didn’t use the method, just left things open for you if you want to put clean up code in there.

This might sound like a dumb question, but does EffectFinished() just get called on it’s own at the end of the effect (where we put finished())? Or do we need to actually call EffectFinished()?

In TargetAquired, you’ll find:

            foreach (var effect in effectStrategies)
            {
                effect.StartEffect(data, EffectFinished);
            }

I will admit, the way it’s written, there’s no data being passed to act on. Sam really didn’t expand much on the method or it’s many possible uses. (I think passing along the data and maybe having a “graceful exit” strategy could help with some issues.

Where in the Ability Script would you go about setting the TimeScale to 0? In use after we get the action scheduler, or before we get the action scheduler?

And I’m assuming setting it back to 1 in the beginning of StartEffect is the right thing :stuck_out_tongue:

So in order to get this to work in my game (going from an ability > back to auto attacking) I didn’t do the timescale thing (when I tried implementing it I think I was putting it in the wrong spots). Instead, what I did was utilize EffectFinished().

What I did was create a new public function in Fighter called
“TargetNewTargetInRange” and I have it set the target to FindNewTargetInRange(); If the target is null, just return.

THEN

in Effect Finished I had the effectUser call that function and it works like a charm (until I find a bug with it)

Actually, I realize the Timescale thing would be a problem with things like DelayedClickTargetting…

The only problem I see with your solution is if I wasn’t in combat in the first place…

Envision a tired fighter walking into a bar with other tired fighters who won’t attack unless they are attacked. Our tired fighter quaffs a healing potion (an Ability) with the intent of chasing it with a beer… but his auto attack causes him to attack the big giant ogre whose minding his own business trying to enjoy a mug of ale… This is how brawls get started!

On a more serious note, I was thinking of adding a DeferAction/ResumeAction to the ActionScheduler, perhaps with an extra interface IDeferActions so that it can test if the current IAction can be deferred, then when the Ability is done, it can tell the ActionScheduler to resume the previous action. I’ll work that up later.

1 Like

Ooo let me know if you get that working!

I don’t think I’ll have, in the immediate future, a passive brawl bar, so I think my solution is a bandaid fix for the time being :stuck_out_tongue:

1 Like

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

Privacy & Terms