Trying to measure distance traveled as an integer

  • Site Migration: See bugs? Report them here. Want something changed or have an idea? Suggest it here.

Sir Nick

L1: Registered
Apr 9, 2018
Hello all, let's talk entities. WARNING: This involves math.

I'm looking for a way to dynamically measure the distance a func_tracktrain has traveled from it's starting point. Why you ask? I'm trying to create (in my opinion) a better capture elevator. The only official capture elevator I can think of is on plr_hightower. This is all well and good, but it has a single set movement speed from top to bottom. What this means is that you only need one person in the capture zone for maximum efficiency, dispelling any incentives to try and get on the point. I am trying to build an elevator that actually moves faster depending on how many players are inside the capture zone.

I can hear you asking already, "why don't you just use a trigger_timer_door?" I'll tell you why; the capture time of a trigger_timer_door is static. I simulated and tested the capture time with 1 player and with 12, and the capture time was the same. If I had to hazard a guess as to why this is, I'd guess that since it was released for use with MvM, Valve didn't want the capture time to stack with more robots. You'd REALLY be in trouble if you let 17 robots past and they almost instantly capped their point.

So why do I need to measure the distance a func_tracktrain has traveled? I intend to use that value in the following equation to give me the perfect sync between capture time and elevator speed, so that they finish at the same time, every time.

Total dist. = (Dist. between bottom and to path_track origins) - (height of elevator)

Remaining Dist. = (Total Dist.) - (Dist. Traveled)

X = The adjustment modifier from the Harmonic Series, used by TF2 for capture rates, as mentioned here.

(Desired Dist. / Desired 1 player cap time) / X:12 (0.322) = Normalized max train speed for 1 player (the max speed you need to set the tracktrain for to achieve your desired one person cap time)

Normalized train speed for 1 player / X(13-n) = Modified SetSpeedDirAccel modifier for n players

If you just set up a logic_case and adjust the SetSpeedDirAccel modifier for 1 thru 12 players it works fine if the player count stays static. If you add or subtract players from the capture zone mid-cap, the speed setting will cover an incorrect distance for the necessary time. Using the method above, I believe I can compensate for both the distance and time change dynamically, thus creating a capture elevator that actually behaves like every other capture point.

The problem is I have no idea how to get the distance the func_tracktrain has traveled as an integer value.

I have two ideas, the first would work flawlessly if anyone know how to make it work, the other would be a pain in the ass and easily broken

  1. Using the logic_lineto, I can create a vector between the elevator and the starting path_track each time the number of cappers changes.The problem is that the logic_lineto returns a vector, when I need a scalar to be used as a float. What I don't know how to do is:
- Use Hammer entities or code to find the magnitude of the vector. Since the X and Y magnitudes will be 0, I don't have to worry about them throwing off the distance when calculating a vector magnitude
- I could also use the Z vec_t ordinate, but I do not know how to access this value within Hammer

2. The other idea is to use a point_angle sensor, and employ some pain in the ass geometry to convert an angular change within a 90 degree span into a linear distance

I realize this is a long post, and it's fairly ambitious, but I am so very close to solving this issue that I have to try. Any help in getting the distance of the tracktrain, using the methods I list above or something else entirely, would be immensely appreciated.

Thanks in advance, and sorry for the math.
Last edited:

Sir Nick

L1: Registered
Apr 9, 2018
I love you. After pulling my hair out for three days, this is exactly what I needed.

Now why on God's green earth is that entity not listed here?!

Mar 2, 2018