Smarter Navmesh Pathfinding

Godot Version

4.2.2

Question

I want to make my enemy pathfind to where the player is going to be based on how long the enemy will take to reach the player. I’m using 3DCharacterBody for both the player and the enemy.

the Navigation built-in in godot should do just that fine, finding the quickest path, what’s your issue with that?

I wasn’t trying to write a new Navigation system, I just wanted to make an enemy that predicts the player using the built-in system. I was successful in doing so, so I’ll leave a tutorial for anyone else wanting to do that.

Here’s how I did the prediction method in the player using a raycast. It might be better to use a spherecast instead, but I wasn’t sure how I would do that.

func predict_position(delta):
	predict_ray_cast.target_position = velocity * delta
	if predict_ray_cast.is_colliding():
		return predict_ray_cast.get_collision_point() 
	else:
		return velocity * delta + global_position

Then, in my enemy

var target_time = global_position.distance_to(target_player.global_position) / SPEED
target_position = target_player.predict_position(target_time)

Then just use the usual navmesh path-finding for the enemy.