jump.tf Forums
Welcome B)

Horizontal velocity HUD Speedometer

SgtPugs

  • Newbie
  • *
    • Posts: 1
    • Frags: +0/-0
    • View Profile
https://drive. google.com/file/d/1rDgBbjfqAXP7J6BtyWlTaKBG8RzVsp-U

Was told to post this here so here it is.

Haven't seen any one manage to get only the horizontal velocity before.

The main limitation of this is that everything is based off /around your average fps. The default average fps is set to 144 but if you dont use/get this I explain how to change this so it can still work in the read me.
Other small limitation is that the way I work out the horizontal velocity has a little inaccuracy as there isn't a square root material proxy, this is mostly fine though as the error is small enough to be around 5% but is still an inaccuracy nonetheless

Demonstration here although I have since changed it to update slower so that it is more readable :)


EDIT -
Version that updates quicker
https://drive. google.com/file/d/1pPEdVNSdTQXQC-y_3L6rRF37gZbM4DLo

EDIT 2-
It is now independent of framerate unless you wanna change how quickly it updates
https://drive.google.com/file/d/15ZU9edavdIm2XVofU8XCxjc9IlvV6gDB/view?usp=sharing
« Last Edit: July 25, 2022, 07:33:55 PM by SgtPugs »


ILDPRUT

  • Newbie
  • *
    • Posts: 19
    • Frags: +1/-0
    • View Profile
This is pretty cool. Didn't think it would be possible since a lot of people said it wasn't. So I decided to figure out how you made it work and then looked up a list of proxies to see what other stuff proxies could do. From the list I spotted an opportunity to make it framerate independent by using the "PlayerSpeed" together with the "PlayerPosition" that you are already using. The basic idea is to extract the frametime by using |PlayerPosition change| = PlayerSpeed*frametime. The calculations would go like this:

speed := PlayerSpeed
pos := PlayerPosition
dpos := pos - oldpos
oldpos := pos

speed2 := speed*speed    // speed squared
d2 := dpos.x*dpos.x + dpos.y*dpos.y + dpos.z*dpos.z    // square of distance moved during frame

dt2 := d2/speed2    // = frametime squared since |dpos| = speed*dt, then |dpos|^2 = speed^2*dt^2, such that dt^2 = |dpos|^2/speed^2

hd2 := dpos.x*dpos.x + dpos.y*dpos.y    // square of horizontal distance moved during frame
hspeed2 := hd2/dt2    // = (horizontal speed)^2 = (horizontal distance / frametime)^2
hspeed := sqrt(hspeed2)    // using newton's method like you're already doing

// display hspeed
« Last Edit: July 25, 2022, 02:25:11 PM by ILDPRUT »


ILDPRUT

  • Newbie
  • *
    • Posts: 19
    • Frags: +1/-0
    • View Profile
Totally forgot about it, but you also need to handle dt2 := d2/speed2 properly if the current speed is zero. So right before that calculation you should put

$one 1
SelectFirstIfNonZero
{
   "srcVar1" "$d2"
   "srcVar2" "$one"
   "resultVar" "$d2"
}
SelectFirstIfNonZero
{
   "srcVar1" "$speed2"
   "srcVar2" "$one"
   "resultVar" "$speed2"
}

This will make dt2 := d2/speed2 = 1/1 = 1 when the speed is zero, which still gives you the correct result for hspeed2 := hd2/dt2 = 0/1 = 0.