Hello everyone,
I am using point and click in a 3D game with unity navigation. I have a building with some small rooms and I am finding that when clicking on walls the character leaves the room and tries to walk to the other side of the wall. This is obviously not what I want.
I think the problem is that the character cant get to the point I'm clicking within the room, so he is leaving the room to try and get there some other way.
I searched the forums and found a topic on this and the advice was to ensure the colliders were on the NavMesh layer, which they are.
It's very important that I fix this as the way I am dealing with rooms is via hotspots to walk to a marker and change the camera, so if the player leaves the room without using the hotspot (they can't usually click outside the room so they shouldn't be able to) the camera will not change and the player wont know where they are.
I'm thinking about solving this somehow via navmesh obstacles that appear in doorways when you enter a room however this is adding another layer of faff. I just wondered if anyone could think of an easier solution.
Ideally I would like clicking on the colliders I'm using for walls to have no effect what so ever and they just block anything clicking behind them (if they are on the navmesh layer the character walks towards them when they are clicked). I've considered creating a giant blank hotspot to achieve this but again it is a faff.
Could I create some kind of layer that just blocks clicks?
Thanks in advance.
Comments
Placing your "blocking" colliders on the NavMesh layer should indeed prevent the player from moving to the next room - though they will still cause the player to move to the point on the NavMesh that's closest to the click. If the collider is closest to the correct side of the NavMesh it should still mean that the player doesn't leave the room.
It may be worth considering the use of Mesh Collider navigation for this particular scene, as this allows for pre-determined NavMesh shapes to be swapped in and out as required. With this method, you could split your rooms up with their own NavMeshes, so that you can't navigate from one to the other without the active NavMesh being explicitly changed.
It may also be worth removing the NavMesh in the doorway, so that the inner and outer rooms are isolated - you could then move the Player along a pre-set Path when you want to move between them, to avoid pathfinding.
A Mesh Collider would still be something to consider. It would require back-and-forth to get the shape correct, but it would give the best result.