-1
\$\begingroup\$

Currently, I am having the problem of converting the physics engine on my 2D game to work frame-rate independent. I have looked at a lot of other questions, but I haven't been able to make any of the solutions there work on my game physics. The problem with changing the physics engine, is that the game already has a lot of "units" that you can be (it's similar to diep.io), and all of those have been balanced out already, and doing a massive change to the physics engine will make it take a lot of time to fix all of the content.

The physics engine works, by running a "physics" function followed "friction" function; where "physics" will add the current acceleration to the velocity, reset acceleration, and add the velocity to the position, and "friction" basically tries to get the magnitude of the velocity to be under a "max speed" value by checking how much higher the magnitude is which is called "excess", then it sets the magnitude (by normalizing then multipying the x and y) of the velocity to maxSpeed plus "excess" divided by a value calculated earlier called "damp" (it basically shrinks the excess speed above max speed down every update, and makes the speed the maxSpeed plus the excess, to get closer and closer to the actual max speed). Some pseudocode of what these two functions actually do:

physics() {
  velocity.x += acceleration.x;
  velocity.y += acceleration.y;
  acceleration.x = 0;
  acceleration.y = 0;
  position.x += velocity.x;
  position.y += velocity.y;
}

friction() {
  motion = sqrt(velocity.x ^ 2 + velocity.y ^ 2);
  excess = motion - maxSpeed
  if (excess > 0) {
    drag = excess / (1 + damp) 
    newVelocity = maxSpeed + drag
    velocity.x = (velocity.x / motion) * newVelocity
    velocity.y = (velocity.y / motion) * newVelocity
  }
}

I've tried multiplying basically every value by a "scale" (which will later on, basically just be how much to speed up or slow down the physics), tried powering stuff, and a lot of other things. Generally, "maxSpeed" is set to 0 for most of the player entities, and "damp" is usually a value from 1-3. Is it even possible to scale this physics system at all? and if so, what should I do to make it do that?

\$\endgroup\$
  • \$\begingroup\$ construct.net/en/tutorials/delta-time-framerate-71 \$\endgroup\$ – Almo Nov 21 at 19:56
  • \$\begingroup\$ @Almo I've already looked at that and tried to do something like that, the problem is I can't actually figure out a way to integrate it to my specific physics system on this game. \$\endgroup\$ – Syncinus Nov 21 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.