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