#Click to move within restricted area

4 messages · Page 1 of 1 (latest)

hardy juniper
#

I have been working on a way to implement click to move into my game. I have a working walkable area. Basically, when the mouse enters or exits the area it sets a bool to true or false, and ”left_click” input requires this bool to be true. The result is that within the walkable area, we can click to move.

On it’s own the walkable area works fine, but what I’ve been trying to implement is a clickable area that extends to cover the whole island. At the end of the day players would click anywhere on the island and expect the player to move. When the game doesn’t respond to your clicks it just feels bad.

So the idea here is that you should be able to click anywhere on the island and have the game figure out the closest approximate area within the boundaries of the walkable area.

Currently it’s set up so that the walkable area has colliders around it, preventing the player from leaving it. The obvious problem with this approach is that when clicking in the clickable area, the player ends up walking endlessly toward a point it can’t reach.

I have been working on different ways of solving this problem for days now and elaborating on them would probably be unproductive and confusing. My suspicion is that the solution is a lot simpler then what I’ve been trying.

An obvious way would probably be using a raycast (following the mouse position) centered in the middle of the walkable area. Hopefully the illustration gives you some idea of what I’m thinking about.

I have no idea how to go about coding something like this though so anything to point me in the right direction would be appreciated 🙂

sick lotus
#

You could just use a navigation mesh and navigation path. There is not much point involving so much physics when all you need is move around a defined surface.

#

like a navigation mesh will automatically restrict the path to its surface, the only way to get outside would be physics ignoring the path and pushing your actor outside.

#

it will also automatically pick the position closest to the navigation mesh when the path target is a position from the player clicking somewhere randomly outside the navigation mesh.