Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
krunkster opened this issue Nov 17, 2023 · 7 comments
Open
1 task done

Comments

@krunkster
Copy link

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

@AlexandreSi
Copy link
Collaborator

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)

@D8H
Copy link
Collaborator

D8H commented Nov 17, 2023

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

@AlexandreSi
Copy link
Collaborator

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

@krunkster
Copy link
Author

krunkster commented Nov 17, 2023 via email

@D8H
Copy link
Collaborator

D8H commented Nov 17, 2023

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.

@krunkster
Copy link
Author

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.

@D8H
Copy link
Collaborator

D8H commented Nov 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants