Garry's Mod

Garry's Mod

Not enough ratings
(Hammer) Setting up pathing for Gunships, Hunter Choppers and Dropships spawned in-game
By OnTheMatter
Hello! This guide goes over how to set up pathing using path_tracks in Hammer for Gunships, Hunter Choppers and Dropships which are spawned in by a player in-game, as when you spawn them in by default in-game they will not follow any path_tracks you have placed down. This is the same method that gm_construct uses.


2
   
Award
Favorite
Favorited
Unfavorite
Introduction
I will be referring to Combine Hunter Choppers, Gunships and Dropships as "Helicopters" throughout this guide, just to keep it simple.

If you want a simplified version of this guide, here is a reddit post I responded to shortly prior to putting this guide together which contains a more straight to the point explanation without pictures. Anyways, the guide is below.

Hello! This guide goes over how to set up pathing using path_tracks for Helicopters which are spawned in by the player, as when you spawn them in by default in-game they will not follow any path_tracks you have placed down. I decided to throw this guide together as I myself had a lot of trouble figuring out how to set this up, and know someone will find it useful. The majority of this information comes from a decompilation of gm_construct, which I found here:

https://steamcommunity.com/sharedfiles/filedetails/?id=2177309827

I recommend taking a look at this regardless as the vmf file itself highlights many good practices. Anyways, without further ado, let's begin.
Lua Spawn-Hook Setup (Not as bad as it sounds)
Let's get the hardest part of this process out of the way. The way Facepunch sets up pathing for spawned-in Helicopters in gm_construct is they essentially set up a function hook to be called whenever a helicopter is spawned in, which sets its path to a single path track first to start out with, which below is called "helipathstart", change this to the name of whatever path_track you want the Helicopter to fly to first. You have to set up a lua_run using a logic_auto, putting the following code into the lua_run :

MAP_HELINPC={npc_combinegunship=true,npc_helicopter=true,npc_combinedropship=true} hook.Add([[OnEntityCreated]],[[map_sethelinpcnode]],function(ent) if MAP_HELINPC[ent:GetClass()] then ent:Fire([[settrack]],[[helipathstart]],0) end end)


You could also perhaps instead just tick the "Run Code on Spawn" Flag within the lua_run instead of adding the logic_auto, I didn't do this but if you don't want to deal with a logic_auto then I would expect it to work but there could be some weirdness to it. If you did use the logic_auto, then you will need to set up the following Output for it :

My output named : OnMapSpawn Targets entities named : HeliPathLuaHook(Whatever you set the name of the lua_run to be) Via this input : RunCode With a parameter override of : <none> After a delay in seconds of : 0

You can set the "Remove on fire" flag to true as well for the logic_auto, I believe it's fine if you forget though.

Randomizing Helicopter Movement
I recommend setting up all of the sets of path_tracks you want the Helicopter to be able to choose from now, as the following steps involve them. Try to make sure each path_track series contains at least 2 separate path_tracks, so there is a start and an end, as otherwise the helicopter can get stuck if it chooses the same path twice. They can be added in later, but you'll need to make sure you update other objects as well. There are guides for this if you don't know how to set up path_tracks. Anyways, let me continue.

Essentially what we have done so far is cause all helicopters that are spawned in to set their path_track to "helipathstart", a named path_track. However, once they get there they will stop moving. To allow the helicopters to randomize their pathing, as gm_construct does, then we will need a logic_case, but first let's set up the output for our "helipathstart".

My output named : OnPass Targets entities named : Heli_randompath Via this input : PickRandom With a parameter override of : <none> After a delay in seconds of : 0


This calls upon a logic_case named Heli_randompath, which will contain a number of cases equal to the number of possible paths you want the helicopter to choose from, just set each case equal to its equivalent number (for example Case 01 to 1, Case 02 to 2, etc.).


Next, for each case within the logic_case, named Heli_randompath, set up a series of outputs as follows :

My output named : OnCase0#(1,2,etc) Targets entities named : !activator (in this case will be the helicopter) Via this input : SetTrack With a parameter override of : PathStartingTrackNameHere. After a delay in seconds of : 0


With both the helipathstart and the Heli_randompath set up the helicopter will first fly to the helipathstart path_track, and then choose a random track from there based on the Heli_randompath logic_case. However, once the helicopter reaches the end of whatever path it randomly chose it will stop. To have it choose a new random path, simply give the final path_track in each choose-able path the same output the helipathstart has,

My output named : OnPass Targets entities named : Heli_randompath Via this input : PickRandom With a parameter override of : <none> After a delay in seconds of : 0

For example, here is the output for the last path_track for the path Helipath_lake(5) in gm_construct.


Once this is all set up, the helicopter should head to the start of a new random path once it reaches the end of its current one. That's about to the extent Facepunch goes with it, and it works fairly well. If Garry himself is willing to settle with this, then so am I. Helicopters act strange no matter what, so don't be surprised if they get stuck on each other, etc. I've noticed as well that they like to stop moving if they are too far away from a player, I'd keep that in mind when designing the path_tracks. Just make sure that the end of each series of path_tracks mentioned in the logic_case contain this output, or else the helicopter will stop once it reaches the end. Either way, I hope this helps!
5 Comments
Sunshine Surreal May 15, 2023 @ 12:24am 
Thank you! :steamhappy:
Вася Feb 18, 2023 @ 8:18am 
Thank you a lot!
Nem T. Lea Sep 18, 2022 @ 4:53pm 
Thank you for the guide, it's really helpful. ^^
OnTheMatter  [author] Dec 30, 2020 @ 5:50pm 
@Bump Attack Thanks for the feedback! I believe the helicopter should still move if it has the same case twice in a row, as long as the path in question isn't only 1 path_track, as it goes from the last path_track in the path to the first. Maybe if they're too close to each other this may be an issue, or if HeliPath_Start is one of the path options, but otherwise I believe it should be okay, from what I've seen the helicopter should just move to the start of the path it just finished if it repeats a case.

It's a good thing to bring up regardless as that hadn't crossed my mind, thanks for bringing it up.

The wall of text is no issue by the way, it's a habit of mine as well. :steamhappy: :steamthumbsup:
Bump Attack ⊗ Dec 30, 2020 @ 11:53am 
Thanks a lot for the guide, it's well written and it certainly saved me a lot of headache. One thing that I wanted to mention is that the helicopter might stopping because the PickRandom input is choosing the same case twice in a row. The helicopter is already at the destination path_track so it never triggers the OnPass output and chooses a new case. PickRandomShuffle should prevent this, but changes the helicopters behaviour a bit. Sorry for the wall of text, cheers to you for making maps interesting! :balloon::physgun::balloon: