I have just completed the tutorial and i want to know if entities can be forced to always stay on a (grid) graph? Unitys native Navmesh does that kind of thing. So if a unit is pushed outside of a navmesh it will be clamped to the nearest location on the graph.
I’ve tested the grid graph a while ago and found out that units will push each other of cliffs into lava, making them kill each other (which is a bad thing). If a unit is clamped to the walkable area, this problem can be avoided. Is there a way to do this?
When using the RichAI movement script on a navmesh graph this system will also do this. Often it is not desirable on grid graphs since the agents may have to cut corners slightly.
It is easy to add this functionality however.
This code can be used to get the closest point on the grid graph
var nn = AstarPath.active.GetNearest (transform.position, NNConstraint.Default);
var closestPointOnGraph = nn.clampedPosition;
Then you can simply move the agent to this position after every frame.
Thanks, so you would suggest to have still the corner cutting movement for the visual pleasure of smooth movement, but if a unit is about the leave to the grid a clamp can be done in a way you presented?
Will this break the movement in some way, when i directly clamp the position of a unit? May he loop in a cycle where he wants to take a path, but is resetted, which leads him to take the same path all over again, but get resetted again?