A* Pathfinding and Random Waypoints [ADVANCED Patrolling]

Enemy state machines really don’t care if the Player has a stateMachine, and these messages are saying that the agent is either inactive (we should check to see if the agent is active before trying to move while in Chasing State), or not on the NavMesh (which our code to avoid getting knocked off of the NavMesh should have covered.

This is a problem that at this point you should know the solution for.

You don’t have a NavMesh on the Player, and it’s erroring on this line… Since there’s no NavMeshAgent, how else could you move the player to the respawnLocation.position?

lol I am done with Malaysia, I was there for education and went back to UAE now :slight_smile: (P.S: I’m from neither :stuck_out_tongue_winking_eye: ) - fun fact, “Al Ain” in Arabic means “the eye” (literally)

lol I used a little, ahem (trying not to get another verbal warning, xD)… trick to teleport the player before he respawns. It works just fine for now, and it’s not teleporting him to wild spots anymore as we speak

I honestly don’t think either is true, they only show up when the enemy is in the attack state of attacking me, but since he can still move around the NavMesh, he should be fine (it doesn’t cause any pursuit errors of any sort)

If it’s a yellow (Warning), that’s a “Oh, wait, I’m not on the NavMesh, but I found it close by” message.
If it’s red, that’s a problem… too far from the NavMesh to connect, etc.

it’s red :sweat_smile: (although it only shows up when the enemy is attacking me, and is causing no issues when he’s pursuing me…)

When the enemy is attacking, he shouldn’t be referencing the NavMesh at all…

trust me, I am as clueless as you are. I went through all the state machines, and apart from a reference in the enemy state machine itself, I found nothing to do with the NavMeshAgent otherwise… (I think all the enemy is trying to do is basically trying to find a non-dead player to attack, BUT he found one dead right beside him so his constant attacks against him are what’s triggering the NavMesh, not sure tbh)

The errors reference: chasing state, idle state and patrol state. But they occur during attacking state. It seems like it is trying to switch state. I don’t see why. What does this have to do with the player not having a NavMeshAgent? This is way beyond my comprehension and it really bugs me.

Wait, this is happening after the player dies??? You need to get better at stating what the problem is.

Ahh, you lost us back there… these errors are relevant to the “Enemy Patrol State”, “Enemy Switch State” and “Enemy Chasing State”, when he tries to hunt me down over the NavMesh Surface

they no longer have anything to do with the player, that issue is (roughly) solved… there are a few occasional hiccups where the player respawns on the spot where he died, but that’s like 5-10% of the time… (and this was there the entire time anyway)

and they only happen when the enemy is attempting to attack the player, and since he still attempts to attack the player post the players’ death, then yes they also still happen between his death and resurrection

but the ‘SetDestination’ takes things one step further and happens one more time after the player has respawned, I think it’s the enemy trying to hunt me down but not finding the proper NavMesh path, and then realizing “oh, I don’t even need to do that…”

anyway, the ‘ResetEnemies()’ code returns the enemy to his default state, so… not a big deal I presume

I wasn’t expecting that… :stuck_out_tongue_winking_eye: (this suddenly became the one thing I wait for every weekend)

Anyway, I’ll go give Bixarrio’s update a go (I asked him for something, he was kind enough to continue helping me :slight_smile:)

Try this small modification in EnemyBaseState()

      protected bool IsInChaseRange()
        {
            if (stateMachine.Player.GetComponent<Health>().IsDead()) return false;
            return Vector3.SqrMagnitude(stateMachine.transform.position - stateMachine.Player.transform.position) <= stateMachine.PlayerChasingRangedSquared;
        }
        

it fixes the issue post death, thank you Brian :slight_smile: (and I can absolutely see why… just can’t see why I didn’t think of that earlier…)

but when he’s still attacking me, the errors still pop up

I’m lost… These errors are when the player is dead or all the time?

Apologies for the confusion. The errors used to be when the player is dead AND whenever the enemy is trying to swing an attack against the player

Now it’s only when the enemy is trying to swing an attack against the player

And despite being red, the characters continue moving correctly?

exactly :sweat_smile: (all that little tweak did, was get them to stop mindlessly attacking a corpse - eventually I would’ve wanted to investigate it anyway, but thank you for saving me from one more error :smiley: )

Privacy & Terms