I’ve created a maze using the top down template as the basis. I’m having problems getting player pawn movement to work correctly when clicking outside of the NavMesh bounds.
What works well The pawn moves towards the hit location when I click within the NavMesh.
What doesn’t work: When I click outside of the NavMesh, the player pawn attempts to move towards the world origin (0,0,0).
What should happen: The pawn should not move towards the world origin. What I want is for the pawn to move as close as possible to the mouse hit location while staying inside of the NavMesh bounds.
My first idea was to make a large plane mesh, create a new trace channel, and force all of the Get Hit Result By Cursor Under Channel nodes to use this new mesh and trace channel for pawn movement. To ensure that the pawn stayed within the bounds of the maze corridors, I wrapped all of my maze meshes with 1 meter tall collision meshes.
This solution solves the original problem of getting (0,0,0) when clicking outside of the NavMesh. However, this solution breaks when I start adding ramps that go below the Z-value of this large 2d plane mesh (see screenshot for examples of these ramps).
Now you might say that I should just lower the Z-value of the large 2d plane. This solves the issue of the ignored ramps, but it introduces a new issue. Since the camera is set at an angle, clicking outside of the maze meshes now sends the player pawn in a slightly different direction than the mouse hit, due to the Z-value difference between the newly-lowered 2d plane and the corridor pieces. This is incredibly disorienting for the player.
I’m not sure what the solution would involve.
- It would be great to not rely on a large 2d mesh for click detection, since generating a (mostly wasteful) NavMesh over the entire 16,000uu x 16,000uu space takes a toll on performance. However, I don’t know another way of getting click detection to get a result other than (0,0,0) in the absence of meshes.
- Perhaps I should replace the Move To Hit Location node with a custom function that sets the player pawn’s velocity and direction towards the hit location?
- It seems like obtaining an XY plane generated from the player pawn’s current Z-value could be useful.
Any help appreciated.