playMaker

Author Topic: Convert speed float to units per second  (Read 1207 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
Convert speed float to units per second
« on: August 29, 2021, 08:37:50 PM »
I get the speed of a object by measuring the distance it moved during a frame and store it as a float.
How do I convert it to show units per second, assuming it continues to move the same speed as current frame, framerate independent?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Convert speed float to units per second
« Reply #1 on: August 30, 2021, 05:55:04 PM »
Hi.
i think if you can figure out what speed you need to do 1 unit then you can just calculate it.

Lets say 20 speed can do 1 unit per second.

then you can do current speed / 20

for example current speed would be 10, then 10/20 = 0.5 units
another example : if current speed would be 40 then 40/20 = 2 units

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Convert speed float to units per second
« Reply #2 on: August 30, 2021, 07:58:47 PM »
Hi.
i think if you can figure out what speed you need to do 1 unit then you can just calculate it.

Lets say 20 speed can do 1 unit per second.

then you can do current speed / 20

for example current speed would be 10, then 10/20 = 0.5 units
another example : if current speed would be 40 then 40/20 = 2 units
I using add force to move the object each frame so using this method would just be an approximation I think.
Is there a way to get the exact duration of the last frame? That would make this very easy.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Convert speed float to units per second
« Reply #3 on: August 31, 2021, 11:40:04 AM »
Which is what delta time is apparently, so I just answered my own question.