GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Regression: Force is not applied consistently when time scale is reduced

Open krunkster opened this issue 1 year ago • 7 comments

Is there an existing issue for this?

Describe the bug

Trying to apply a force to a physics2 object does not work consistently when time scale is reduced. Sometimes it will work but often it fails to apply the force at all.

This is a regression in 5.3... well somewhere between this spring and 5.3... sorry I don't know which version I upgraded from exactly... but it was probably 5.2.168

Steps to reproduce

issue-force-time-scale.zip

Attached simple reproduction.

  1. Click inside walls
  2. Ball is applied a force towards mouse
  3. Ball will idle after 1 second
  4. Click "Game Speed" text to reduce time scale to 0.25
  5. Click inside walls
  6. Ball doesn't move, but will idle out

GDevelop platform

Desktop

GDevelop version

5.3.180

Platform info

Windows 11

Additional context

No response

krunkster avatar Nov 17 '23 04:11 krunkster

Hi @krunkster, Thanks for the detailed report and the project! There are 2 things to consider:

  • While you are setting the scene timescale to 0.25, you should also set the Physics extension time scale to 0.25
  • I tested this but there is still an issue so I suggested a fix

I'm surprised it used to work before but still, this fix gave a result that felt natural to me with the project you sent (each click is considered and the ball reacts accordingly with a similar feeling as when the time scale is 1)

AlexandreSi avatar Nov 17 '23 14:11 AlexandreSi

Forces are used for things like thrusters, it must not be used as a way to set a speed.

image

Please use the "Apply impulse" action instead.

image

D8H avatar Nov 17 '23 14:11 D8H

@D8H's answer is more pertinent than my Pull Request (I've been too hasty), you should apply their recommendations

AlexandreSi avatar Nov 17 '23 14:11 AlexandreSi

"D8H's answer is more pertinent than my Pull Request (I've been too hasty), you should apply their recommendations."

I’m not sure how the reproduction provided indicates that I’m trying to set a speed rather than apply a force?In my actual game I want to apply a force to simulate the reaction of one object being struck.  Think like a ball and bat or golf.  I believe in this case a force is more appropriate than an impulse.

krunkster avatar Nov 17 '23 15:11 krunkster

I’m not sure how the reproduction provided indicates that I’m trying to set a speed rather than apply a force?In my actual game I want to apply a force to simulate the reaction of one object being struck. Think like a ball and bat or golf. I believe in this case a force is more appropriate than an impulse.

An impluse is a not a speed, it's an impulse of force. A force at an impact that is applied only once. It's a bit the same as changing the speed but the mass is taken into account.

Where as the "Apply force" action is a force that is apply over a period of time, while the action is used. If this action is called only for one frame, the force is applied during 1/60 of second at 60 fps and 1/30 of second at 30 fps.

D8H avatar Nov 17 '23 15:11 D8H

Thank you for your help, and I appreciate that the docs and help text have been updated over the last year as well. Unfortunately, I'm in a situation where I have a big game that's behaviorally 90% done that relies on the old behavior of "Apply force". I see that "Apply Impulse" and "Apply Force" both take a Length argument... N*s and N respectively. You also implied that "Apply Force" used in a single frame is affected by the frametime which would be 0.16s (60FPS). So can I convert Length arguments here by multiplying by 0.16.... or do I need to take mass into account? If there is a way to 1:1 convert and preserve behavior then I think that's feasible for me... otherwise it's a devastatingly huge task and I'm better off reverting versions.

krunkster avatar Nov 17 '23 16:11 krunkster

Yes, you can divide by 60 when replacing a force action with an impulse action.

D8H avatar Nov 17 '23 16:11 D8H