Player and enemy hit at same time, breaks nav mesh?

Hello,

When both the player and enemy hit at the same time, the enemy keeps trying to walk towards the player, but never gets closer.

If I try and walk towards the enemy it keeps the same distance away, but always has the walk animation playing.

Looks like the distance is the combined amount of our knockbacks.

It also seems to crash my unity when i end play mode.

Thanks,

1 Like

Hey @Caesura, it would be helpful if you posted what error codes you get in the console to better understand what is happening. And a screenshot of your inspector settings for your navmesh agent, and enemy state machine similar to these



ones

The only difference is my attack knockback is at 8.

The crash isn’t happening at the time, but if i hit the enemy around the same time they hit me, it creates this forced gap between us still.

Is it possible to pause the game without it crashing and check in the scene view on the position of the enemy and its components.
I admit this is not an issue i have managed to recreate.

I have no idea why this would crash Unity (it shouldn’t!).

You’re experiencing forces acting against one another. Each ForceReceiver is being given both charge forward data (from the AttackState at the prescribe time), AND the knockback from the attack at the same time. The net result is that they sort of cancel each other out. This is expected behaviour just because of the physics involved.

Rather than using a timer to leave ImpactState, try testing to see if the character is still impacted in the ImpactState’s Tick method… Put this method in your ForceReceiver:

public bool isImpacted() => impact.sqrMagnitude>0;

Then in the Tick you can test isImpacted() and switch states when it’s no longer impacted.

1 Like

Hey @Caesura, without you posting more info like your Scripts / a video of the issue/ unity version/ any changes you made to the course material/ Console message/etc there’s not much I can help you with :neutral_face:

The only issue I had with combat was a missing bool check in the Enemy Chase State. In EnemyChaseState.cs - Exit Method add the follwoing

  public override void Exit()
    {
        if(stateMachine.Agent.enabled==false){return;}

        stateMachine.Agent.ResetPath();
        stateMachine.Agent.velocity = Vector3.zero;
    }

The force receiver enables and disables the agent on knockback, and the ChaseSate is trying to Reset the path resulting in this error (and the enemy running in place)

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

Privacy & Terms