0

Im trying to implement point and click movement in my game, but at the moment im stumped about how i can select parts of a mesh for the player to walk to.

So what ive done is ive got a navigational mesh in my game, i can select points from it, but what i want to do is be able to select the navigational mesh in real time and be able to tell the player where to go on the navigational Mesh, how can i achieve this?

I thought triangle-picking might be one way to determine where im selecting the mesh with mouse unproject but i think i need a bit more accuracy than that, no?

How can i achieve point and click on a navigational mesh in real time?

Thanks

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Clockworks
  • 41
  • 7

1 Answers1

1

Disclaimer; I haven't used navigational meshes myself yet. But I would think it would work something like this:

I would guess you should have this mesh in some kind of data structure that makes spacial searh easy (quad-/octree). You would then cast a ray from the mouse pointer along the camera.

https://gamedev.stackexchange.com/questions/26106/screen-space-to-world-space

you then do a search in your mesh, using the datastructure to reduce the number of points you need to check.

If your mesh is essentially flat, you can also just use a fictional plane. This simplifies ths drasticly as you get a 3d-position that you can search for the nearest nav-point to instead of a ray to check intersection with.

An other way of doing selection in 3D is to have an off-screen rendertarget that each selectable draws a special color to. You then just need to check what color you clicked and look that up in a Dictionary or something. Don't know how this would work with a navigation mesh, though.

Edit (Quadtrees); Quadtrees in this context are basicly a way of distributing elements in your game by location. usually they are axis-aligned and positioned around the world origio ([0,0,0]). What they do is basicly splitting your list of elements into 4 based on which quadrant of the world they exist in on the x-z-plane. Let's call these Nodes. So if you look for an element that is close to an element at [10,0,15], you would look in the list for the node that belongs to quadrant [>0,*,>0].

As your nodes get a lot of objects in their list, you split them into 4 again. So if your node is [0, -100, 0] to [100, 100, 100], the children will be:

n0: [0,-100,0] to [50,100,50]
n1: [50,-100,0] to [100,100,50]
n2: [0,-100,50] to [50,100,100]
n3: [50,-100,50] to [100,100,100]

All nodes have a BoundingBox that you use to check intersection with to decide if you should continue searching inside the node.

Case: Object @ [20,10,20] wants to find objects within 10 units in a world with 1.000 objects distributed from [-100,-100,-100] to [100,100,100];

  • Create a BoundingSphere around the position with radius 10.
  • Intersect-test 4 top-level nodes. n1 returns true ([0,-100,0] to [100,100,100])
  • n1 has its own children, so we intersect them also. n0 returns true ([0,-100,0] to [50,100,50])
  • n1/n0 has no children, so we check the 62 objects in its list and return those that has boundingspheres/boxes that intersect with the range-sphere.

This way, we search a list of 62 objects instead of one with 1.000. to reduce the number of intersect-checks by 937 (we wouldn't check against the object itself anyway), we only had to do 8 intersect-tests; all top-level nodes (4) and n0's children (4).

So intersect-tests went from 999 to 70. THAT is progress :)

Community
  • 1
  • 1
  • Thanks for the prompt reply. I've got my navigational Mesh information in an array but can it be passed to an octree? I've done flat conceptual-world pathfinding which the world coordinates are translated from conceptual pathfinding coordinates, i find this is great but greatly limits movement. My levels are getting a little bit complex so navigational meshes are necessary for me to be able to use the Y axis. I will research into octree/quad datastructures now. – Clockworks Mar 13 '13 at 08:08
  • Ok, then you should probably use a horizontal quadtree. I will edit my answer to explain a little. – Stig-Rune Skansgård Mar 13 '13 at 08:43
  • Horizontal quad-tree? Is this in regard to me pathfinding on a single plane? Im not doing this anymore by the way. Im using navigational meshes now. – Clockworks Mar 13 '13 at 09:04
  • No, I mean that to be able to figure out which node/point on your mesh you are clicking, you need to be able to search the mesh using a ray. If you have too loop through all nodes/points and test intersection with the ray, it will be "too slow" (depending on number of points, osc), so you should use a tree to split them into more managable pieces. – Stig-Rune Skansgård Mar 13 '13 at 09:10
  • You can "re-imagine" my example case to be testing a ray instead of a boundingsphere, and triangles on your mesh instead of objects. – Stig-Rune Skansgård Mar 13 '13 at 09:17
  • This is an absolutely great answer. I've learnt so much through your explanation. So what im going to do is split my world up from 0,0,0 to 100,100,100. So n0: 0,0,0 - 50,100,50. n1: 50,0,0 - 100, 100, 50 n2: 0,0,50 - 50,100,100 n3: 50,0,50 - 100, 100, 100 Then i split those nodes up further by 4 ? Then inside those nodes i should be able to check for intersection by creating a bounding sphere that detects up to 10 units? – Clockworks Mar 13 '13 at 10:39
  • Basicly, you split nodes into child-nodes when the number of elements in them reach a certain threshold. You should make this threshold adjustable on some level, so that it is easy to tweak. Also remember that you need to populate the tree. This is done by checking intersect with Nodes and adding the element to nodes it intersects with. A point with a radius can be in more then one node, dependng on position. – Stig-Rune Skansgård Mar 13 '13 at 12:44