Question about terrain hugging using raycasts

Hi Everyone,

Context: Currently in the process of navigating an aircraft through a maze of mountains. The aircraft should avoid the mountains however can have it’s altitude altered by user input.

Potential Solution: Raycasts. I’m using two (one out each side of the aircraft a little offset from the front) to keep a constant mid-point position to essentially hug the terrain. Although this doesn’t really make for a nice weave through any sharp turns. Also considered using what I’m calling a “scout” that flys ahead of my aircraft and all I use in the aircraft’s physics scripts is a transform.lookat(scout). Still not ideal.

Question: Better method? What would a more able developer use? I know that you can use navmesh/navmesh agents, but for flying?? And also navmesh is a pro only feature (that I can’t afford).

Thanks in advance!

You could use any old A* path finding algorithm (A* Pathfinding Project has a free version, there’s an implementation on Unity Gems too).

A grid based approach for building your navigable map would be good - but if you want different weaving at different height levels then you will need a complete cube grid, rather than a 2D map or at least multiple levels of grid.

Another choice would be to use more “feelers” - more ray casts that operate like an unknown pilot navigating the terrain. A whole range of such sensors could then feed into an algorithm to decide on the direction to fly.