How to determine the time for a missile to get to a target

I’m sorry if this is in the wrong section, this is my first time posting somewhere other that in serverhosting.

This isn’t necessarily a problem but I need help from more experienced people than me because I can’t completely figure out how to do something in the game.

I created a truck that has a nuclear missile launcher on the back, and I though it would be handy if there was a screen that gave an estimation of how long it would take the nuke to get the the assigned target.
Basically I know (as most people should) the basic math that time=Distance/Speed. I figured that would be easy to apply in game however it was more complicated then I thought as the final estimation was not totally consistent. First, I used a laser pointer to make the target and put a GPS on the truck (I had to use this combo as there is no way to measure out the distance between the truck and the target in wire tools so I would have to measure the distance every time with an addon to do so which would be stupid and ruin the whole thing). To find the distance part of the equation is a bit strange as the gps and laser pointer measure in coordinates. So I made 3 subtract chips all equating, GPS-Laser Pointer Receiver, one for each axis (x,y,z)
The I made 3 absolute chips because it didn’t matter whether it was a negative difference or positive in between the truck and target, only the actually number difference mattered. So after that all the axis’s were positive. Before creating the actually machine I launched a missile and froze it. I then tagged a speedometer on to it and outputted to a screen (this is where the first major problem is). I had no idea what measurement the game uses for the coordinates so for the speedometers output I assumed to use the output: out (in which I discovered the missile traveled at 198o/s which the o is the output out because I don’t know what distance 1 out is). So to complete the /speed I just made 3 divide chips and on each one equated, Absolute/constant value (of 198) for each axis. So I had the time It would take for the missile to reach each axis’s target how ever I needed to put them together. The only way I saw to do this was to average the axis’s times. So after that I ended up with a number.

The problem is that the number isn’t very close to the actual time for example it estimated 25 seconds once when it only took 11 seconds. I can see my self that there are many problems with my workings however I have no idea how to do it any other way.

Any help or suggestions are greatly appreciated (perhaps an addon to measure distance between to points with wire, or a tool wire has to help accomplish this that I don’t know about?).

Get that speedometer working right. it should have options like mph or kph and in there i think there is some coordinate option. Just get the distance thing to match the format of the speedometer then you’re all set.

(i would try it sounds cool but im stuck on a mac for the while.)

To measure the distance between two points, use Expression 2.


@name Distance
@inputs X1 Y1 Z1 X2 Y2 Z2
@outputs Dist
@persist
@trigger all
Dist = vec(X1,Y1,Z1):distance(vec(X2,Y2,Z2))

If you want Vector Inputs instead:


@name Distance
@inputs Point1:vector Point2:vector
@outputs Dist
@persist
@trigger all
Dist = Point1:distance(Point2)

Also posted this here: http://www.facepunch.com/showthread.php?p=16715296

Thanks that makes the whole thing a lot easier. Though i have one last question. What type of distance does this output because the speedometer only outputs Kilometers, Miles, or just like I said before Out.
So I have the distance and time parts of the equation good but for the speed I need to match up the type of speed and distance or it won’t work properly (no duh)

So basically what out put of the speedometer should I use to match the type of distance outputted in your instructions?

This outputs Gmod Units. Which I believe is Inches.
If you want to change this into something else, have a look here: http://wiki.garrysmod.com/?title=Wire_Expression2#Unit_Conversion

Example:


Dist = toUnit("m",Point1:distance(Point2))

Will convert it into Meters.

Thanks that helps a lot. It works perfectly and is on the dot with the calculations :smiley: