Knockback using Navmesh

Hey guys!

Another question from me,

I’m trying to simulate knocking back an enemy when they are hit by the “box collider” I have attached to the players weapon. I was just wondering how I could push the enemy backwards, away from the player using a Navmesh command/function rather than using Addforce, which is what I have implemented currently. As it throw my enemy’s off of the navmesh and they slide around.

Any and all help is appreciated!


set the destination equal to a point x distance along the vector goes from player to ai.

direction = ai.position - player.position;

distance = 1;
destination = direction * distance

this would make the destination 1 unit (a unit in unity is 1 meter) or approx 3 feet away from the player in the direction of the ai character.

Assuming the players are scaled right (a normal sized human is approx 2 units or 6 feet in height) and the ai is standing very close to the player the ai would move to a position just under 3 feet away. Thats one way to do it though it kinda makes the AI run there if thats the animation its under. You’d need a knockback animation that shows him going through the air or however you want him to look when knocked back and orient it with the front towards the player so that as he moves toward the destination he still faces you and APPEARS to be knocked back, if you bump up the speed to fast and give it the right animation he’ll move quickly backwards while facing you and basically he’ll be knocked back.

You said he was knocked out of the navmesh why exactly? does the nav mesh not fully encompass your terrain? how is he getting knocked off it?