Hello!
I need help setting the colliders for the player and NPCs.
Initially, by setting the NPC with the same settings as the Player, when I gave him the "follow player" command he would go past any collider, but by fiddling around a bit with the NPC and rigidbody settings I was able to get him to stop by the colliders (which in the video are seen as red rectangles).
the problem is that now I would like the NPC when following the player to be able to find an alternate path and not get stuck in front of the collider.
But this makes me think that there is a whole "setting" part that I have completely ignored, also because I tried something else:
I tried giving a "move to point" action to the player (in the final part of the video), and even he when he gets the action and moves on his own ignores any kind of collider.
I can't figure out what I'm doing wrong, thanks in advance for any kind of help!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
ok I think I got it, I just needed to add holes in the navmesh.
The only problem I am experiencing is that when the player or npc needs to find the path near an obstacle and it is near the edge of the navmesh, it tends to find a path that intersects between the collider and the navmesh.
https://imgur.com/a/5KFuDnp
I think I solved it by making the navmesh much wider than the edges of the walkable area that I went to make up with a collider that more or less follows the end of the background sprite, because I have direct as the input method. I don't know if this is a good solution.
Then I have another question:
can I give as holes in the navmesh colliders that are not polygon colliders?
Let me explain better, I would like all the game colliders to end up being holes in the navmesh, do I have to load them all by hand and only using polygon colliders? Or is there a better method that I am missing?
Thanks in advance!
Are the areas to avoid dynamic, i.e. they can be enabled/disabled at runtime?
If not, it's best to embed them into the original Polygon shape.
Otherwise: with Polygon Collider pathfinding, the behaviour works by adding the new shape as an additional polygon to the based collider. The exact resulting mesh can vary a little if the "hole" leaves the original NavMesh. It's generally more reliable when contained entirely by the NavMesh, but it should be possible to have it carve out from the side - try positioning the outer vertices very close to the NavMesh's edge.
Another option is to create a separate NavMesh - with the holes embedded into the shape - and then swap it out with the original at runtime.
I'm not 100% clear on your meaning - but the "hole" system does require the use of Polygon Colliders.
Thank you Chris for the reply!
Unfortunately, I can't figure out how to see if the areas avoid dynamics. But I used both the colliders created with the adventure creator button (so they have the collision script) . Either I created them by adding a simple box collider to a sprite.
I also created a group of colliders that deactivate when the player presses the jump button and then reappear at the end of the jump, so that he can jump over small obstacles.
I think the simplest solution is to create the navmesh at the end of the full scene construction, this avoids all the problems.
As I showed in the video, making the edges of the navmesh wider, is problematic because it unfortunately makes my NPC leave the edges when it has keep out of the player's way active.
On the last question, sorry for not being clear, but I meant if in addition to polygon type components other components could be used, such as box and sphere. But I think the answer is negative.
Thank you for everything!
Apologies for the delay, but I've looked into this to see if there is an easier workaround - and there is, through the use of the alternative pathfinding method, A Star 2D.
If you switch to this in the Scene Manager, navigation will then rely on the A* algorithm, which involves dividing the NavMesh into a grid. When a hole is added to it, grid cells that lie within it are removed - so the results should then be as intended. Give it a try and see if it works - results look good on my end.
When using the A* method, you aren't limited to Polygon Colliders for your main NavMesh - any 2D Collider is valid, including the Tilemap Collider. However, if you wish to rely on holes to carve out portions, the use of Polygon Collider becomes necessary again.