Move player to mouse click location

How might i go about setting up logic nodes so that i might right click on my mouse, my character moves to the area on the navmesh click on by the mouse cursor?

i have a nav agent on my player, and have generated the navmesh, but i cannot for the life of me, figure out the logic behind it

so to sum up, on right click, raycast from camera, to nav mesh, use that x&y location to move my character to

any help greatly appreciated

Hi,

This is not tested, but should work for what you want. Make sure you have a rigid body added to the navmesh.

Note: The navmesh created from the “generate” button is only for visual confirmation. And is not actually used in game. So deleting it will not have any effect. What matters is the mesh from which you generated the navmesh. Add the RB to this mesh. Not the generated one.

Hope this helps. :slightly_smiling_face:

Thanks for the quick reply, however, when i click, nothing is happening
ive set the nodes exactly as you said

does it matter that the logic nodes are on my player?

again, greatly appreciate the help here

1 Like

Then we need to debug this :wink:

A few things you can do:

  1. Check if the Blender system console has any errors or warnings.
  2. The NavAgent bundled trait must be applied to the player object. Only then the player can navigate the navmesh.
  3. You can use a print node to print out the object and position hit using the ray cast. This would give an idea about the rigid body and collision masks.

No, it need not be on the player. But the player object must be selected on the Go To Location node.