So the NavigationAgent.Velocity should have been set using a Timer instead of the _Process function? Give me a few minute, I need to try it.
Sorry my last message was wrong i think. is it normal that Velocity is written with a capital V in C#?
Yes, most variable in C# is written in PascalCase. Also, the issue is fix (albeit in a sketchy fashion). The agent would go off boundary and manage to avoid the obstacle thanks to it less frequent update; rather than the algorithm tell the agent to go around the obstacle. This shouldn’t be considered as a solution to the problem I’m fixing.
Oh, I should note, this fix only work for obstacle with convex shape (in an unreliable fashion) and fail to work on non-convex shape depend on the angle the agent approach from.
To all the people who may come to this post in the future, no solution for my specific case is found. However, here are some solution that has been suggested that may work for you:
- Watch this tutorial: https://youtu.be/yT22SXYpoYM
- Set radius in the inspector to an appropriate value.
- Set avoidance_flag to true in the inspector.
- This answer (I don’t quite get it but maybe you do): How to use NavigationObstacle2D - #10 by smix8
I encountered the same problem. What surprised me was that the obstacle avoidance between agents was indeed effective. Before multiple agents collided, the velocity of the agent was changed to achieve obstacle avoidance. What puzzled me was that the velocity did not change when the agent met the NavigationObstacle2d. I tried for a whole afternoon but couldn’t find the answer. If any one figure it out, please tell me, ths!!!
Hello! I apologize for the delay, but here is the answer:
- NavigationObstacle2D only prevents NavigationAgent2D from entering a zone; it doesn’t make it navigate around it.
- To achieve this behavior, you need to either re-bake the NavigationMesh2D with a hole representing the obstacle zone or use NavigationAgent2D with an appropriate radius to act as an obstacle (this is not recommended as it may cause confusion later).
Why this is happening:
- Pathfinding is a resource-intensive operation, so mesh baking is the best solution for applications requiring high performance (Some games don’t need this, but it’s crucial for a game engine).
- NavigationObstacle2D has custom shapes and sizes and isn’t necessarily static, making it costly to re-bake the mesh and difficult to integrate into the agent’s pathfinding.
So why even use NavigationObstacle2D?
- As mentioned, it’s to block an agent from entering a zone temporarily without making the agent choose another path. (For example, an enemy being blocked by a destructible door).
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.