Set navmeshagent destination to an area rather than a Vector3
I have some monsters that will chase the player using navmesh and when they are close enough they start attacking. However, if the player jumps ontop of an object such as a table or a bed, the navmeshagents doesnt know what to do since the transform of the player is too high up and start trying to find different paths to the player such as going to another floor of the map and so on.
Since my agents doesnt have to be at the exact position of the players transform, i would want to set the destination to an area around the player, such as a sphere or a cube so that the agents would still move towards to player until they are a couple of meters away from the player. How can I achieve this?
Answer by Empowerless · Jun 30, 2020 at 07:23 AM
Set a variable that tells the destination has been reached when the agent collides with the destination sphere or cube?
The problem is that if i jump on a table, the AI doesnt go towards the players position anymore since it cant reach the exact position, rather it either tries to get close another way (from the floor above), or the ai doesnt move at all
Answer by mrcomplex · Jun 30, 2020 at 12:32 PM
You can check the distance from enemies to the target player. I don't know how's the logic of your enemy looks like, but you could insert something similar to this on the enemy's movement script:
float StandAndAttackDistance = 2f; // never mind the verbose variable name :) if ((Player.position - transform.position).magnitude <= StandAndAttackDistance) { //Start attacking }
Hopefully this is what you were seeking for? @unity_MtfWb1YYVBkEPQ
EDIT: sorry for the missed up formatting =/
Your answer
Follow this Question
Related Questions
Ai Destinations not changing when using length of raycast, 0 Answers
Artificial pathfinding with colliders 0 Answers
How do I make AI objects not walk on top of each other? 5 Answers
Spawning object with new random pathing.,Randomly moving after spawn 0 Answers
Making the AI to reach the destination without a Navmesh? 0 Answers