As Soon as I now press play all the Enemies start playing the attack animation

After implementing this lesson, as soon as the I press play all the enemies play the punching animation. They stay still till the player comes in view then give chase. But still playing the punching animation.

I have been through the GitHub for this lesson and my code changes are identical. This did not happen in the previous lesson where we just Debug.Log out the should give chase message.

The only thing I have noticed is on my Enemy prefab. When you click on the override button it only gives me the option to Revert or Apply all to the Base, which I am guessing is the character and that is not something I want to do. And this does not occur with my Player prefab

Any help or suggestions would be greatly appreciated

Are your enemies using the same animator as the player? If not, paste in a view of your Animator (the boxes with the arrows) and we’ll see if we can figure out what’s going on.

Hi Brian,
Yes both enemy and Player share the same animator controller, I do not believe we have spilt them out yet? Or have I missed that??

Please see animator with the different transitions highlighted. Thanks again for your help.



Check to see if there is an Animator on the model of the enemy (it’ll be on the Character_Knights_Soldier_01 object). Sometimes this can interfere with the animator at the Enemy root. Try removing it.

Just a probably unrelated question: are those transitions right? I see multiple transitions back from attack. One without a condition and one with a condition. I’m curious as to how the state machine would handle those…

Those are correct. One transition without any conditions that works off of HasExitTime, and one for cancelling an attack prematurely with the StopAttack trigger.

OK, thanks. Disregard my post…

Good Morning Brian,
There is only one Animator on the Enemy Prefab which is at the root layer. I have already deleted the additional animator on the “Character_Soldier_02_Black”. As I thought it could be an issue. And the Player is the same only the one Animator on the “Root” level, not on the child “Character_Knight_01_Blue”

Many Thanks
Paul

So at this point, the only difference between the Player and the Enemy on the Root should be that the Player has a PlayerController, and the enemy has a CombatTarget and an AIController.

Both should have an Animator, a NavMeshagent, Mover, Fighter, and ActionScheduler.

To clarify, are the enemies playing the punching animation once and then not playing it again until the player enters chase range, at which point they play it continuously? Or are they playing the punching animation continously regardless?


And the enemies start punching animation as soon as the game begins

Paste in your AIController.cs script (the text, not a screenshot) and your Fighter.cs script, and we’ll take a look. This is a bit of a mystery, as I can’t see any reason so far that the Enemy would be stuck playing attack while the player functions normally – one of the reasons we use the same components between them is to eliminate oddities like this.

Fighter.cs


For future code pastes, always select the code in your code editor and copy it, then paste the text directly into the reply here. It’s very difficult to read screenshots, and sections like the 3 dots before GetIsInRange() hide code. It’s also difficult to copy and paste relevant sections for correction.

It’s possible that part of issue is in Fighter, in StopAttack().

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

For StopAttack(), you’ll want SetTrigger("StopAttack"); and `ResetTrigger(“Attack”);

Thanks very much Brian that was it.
And yep point taken about code :slight_smile:

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

Privacy & Terms