playMaker

Author Topic: Odd results from delta time  (Read 748 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
Odd results from delta time
« on: September 05, 2021, 07:36:29 PM »
I have trouble understanding what's happening here. I divide the distance an object moves per frame with delta time to get its speed. The problem is that the result is very jittery and not accurate at different frame rates. The result is somewhat accurate at 50-60 fps, around 7. But at 140+ the speed is almost 0.(the object is moving correctly at any fps btw)

I then tried to multiply the distance with the fps. It made a much less jittery result, but the speed displayed at the different fps is the same as above.

I've learned that getting such result might be because you make the calculation in fixed update instead of in update.(the object moves by the physics system)

I got all the advanced versions of all actions, from getting position to getting delta and the calculation. I made sure they are all set to update in update, each frame and they are in 1 state. I've also tried all the different ways to get delta time from the time info action.

Despite this the result is still as if you do it in fixed update. What can I do?

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Odd results from delta time
« Reply #1 on: September 06, 2021, 03:02:31 PM »
Apparently I got the wrong info, you are supposed to do this calculation in fixed update. I know that you are not supposed to put delta time in fixed update, but it works perfectly.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Odd results from delta time
« Reply #2 on: September 06, 2021, 03:37:55 PM »
Hi.
Can you give more details on the use case?
As this looks like not a very performance friendly way.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Odd results from delta time
« Reply #3 on: September 06, 2021, 04:20:49 PM »
I'm not sure what you're asking, but I only get the distance an object moved during one frame, remove the Y positions, and divide by delta time. What's wrong with that?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Odd results from delta time
« Reply #4 on: September 06, 2021, 04:35:33 PM »
Hi.
i mean what reason you need the data.
Are for example displaying the speed of a car running.

maybe you can get it like every 0.1 sec

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Odd results from delta time
« Reply #5 on: September 06, 2021, 04:52:15 PM »
Ok, I need it to see the players current speed and adjust acceleration based on it. I don't want the player to push against a wall and suddenly launch like a cannon if he rounds a corner, for example.

I've tried to do it in intervals like that, but the result is always wrong or very jittery.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Odd results from delta time
« Reply #6 on: September 07, 2021, 07:19:21 AM »
Hi.
Does the 'Get Speed' action not work?

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Odd results from delta time
« Reply #7 on: September 07, 2021, 08:05:57 AM »
That's for rigidbody only. I fiddle with the speed variable so I need a way that works on everything.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Odd results from delta time
« Reply #8 on: September 07, 2021, 06:08:50 PM »
Hi.
Maybe a 'Float Smooth Damp' can help.

I use this on a droid that follow our player and when hes far i gradually increase velocity and when closer he slows down.

But it might also help in your case not to have large differences.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Odd results from delta time
« Reply #9 on: September 07, 2021, 08:51:00 PM »
Yes I actually checked that action but I have too many changes in gameplay depending on your speed, so I ended up making my own system.

But, to get the speed I found that using smoothed delta time during fixed update creates a very solid result. Even at low fps then things start to get jumpy, all you need to add is a small filter that removes spikes and it's perfect.