Multiplying by delta not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Odion

In my project I started without taking in consideration delta so it runs equally in evey PC. Once I realized my mistake I had already made the movement how I liked it so I created a variable called NORMALIZE that would multiply delta * 60 fps because that’s what I been working with.

   var NORMALIZE = delta * 60.0

In my head this would normalize the movement to the way I liked it. I then multiplied to my accelerations:

acceleration.x = ((walk + friction + wall_jump_x + external_force_x) * margin_error) * NORMALIZE + offset
acceleration.y = (gravity + jump + wall_jump_y + external_force_y) * NORMALIZE

These are all my forces in the y axis and x axis. What happens tho is: if I put less fps, lets 20fps, my NORMALIZE will go to 3 (instead of 1) as expected but my character jumps a lot higher, even though, I thoought it would decreased. What am I doing wrong?

What function does the posted code live in?

jgodfrey | 2020-11-24 19:28

:bust_in_silhouette: Reply From: NewUser2000

Acceleration works over time and doesn’t return to zero after a frame. So you’re setting the acceleration of a jump (that lasts multiple frames) from the delta from a single frame. So if you happen to jump at 20 fps you jump 3 times as high, and if you jump at 120 fps you jump half as high.

_physics_process() runs at constant rate always and is probably what you should use. No normalizing needed.

What I thought about normalizing is thinking about if in someone’s computer it can’t run at 60fps? What would happen then?

Odion | 2020-11-24 23:42

Have a look at the documentation for _physics_process(). It is tied to the physics simulation instead of the frame rate (fps) that _process() is. So fps doesn’t matter when you’re in _physics_process().

NewUser2000 | 2020-11-25 02:14

Yeah Ive read that. I understand that it’ll run alsays at a set fps. But what if the PC can not run the 60fps because lf performance. Let’s say it can only run the game at 40 fps. Won’t the script be forced to run only at 40fps.

Odion | 2020-11-25 08:34