How do I make 3d navigation tiles be pickable by raycasts from mouse?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All!

I’m trying to use 3d path finding with navmesh tiles and gridmaps.

In my mesh library i have plane tiles, each of which is a mesh instance (plane) with navigationMeshInstance as its child.

In the main scene, the tree is:
Root node
– Navigation

This works for nodes which move along paths towards targets whose global transforms are set in code.

BUT, the player node is to move along a path from whatever its position towards a clicked point (point and click movement).

I’m using this function to return the target point for the player node:

func raycast_from_mouse(mouse_position, collision_mask):
	var ray_start = camera.project_ray_origin(mouse_position)
	var ray_end = ray_start + camera.project_ray_normal(mouse_position) * ray_length
	var space_state = get_world().direct_space_state
	return space_state.intersect_ray(ray_start, ray_end, [], collision_mask)

I then set the collision mask in a separate function which returns a ‘collider’ point towards which to move.

This method works great for baked navmeshes but the raycast doesn’t seem to be colliding with meshlib tiles… Anyone know why?

Right, solved. Found the answer in the docs. The intersect_ray method only collides with bodies, which I managed to overlook. My tiles were just meshes with collision shapes… There I go.

Macryc | 2020-04-09 05:43