[Question] Very Inconsistent function between computers.
See original GitHub issueI’ve been working quite heavily on the “Physics” for our game and we’re quite happy with the movement system that we’ve created so far thanks to all of the information available online.
We have tested this on 7 computers and only 1 has had the issue.
Here’s a few parameters that I can guarantee:
- All Computers are using intel processors
- All Computers are using NVidia GPUs
- All Browsers are up to date
- Problem is PC specific, not browser specific from what I can tell. (Chrome, Edge, Opera, Firefox, issue exists on all or none)
- All tests are run from the piqnt space using the
planck.testbed
- All PCs are running windows 10.
Here’s the code that’s causing the problem (note: we stripped everything away until this was the last thing) in testbed.step
: Code also found in iForce2D (Moving at a constant Speed) We’re using forces for everything where possible not manually setting the velocity at all. All objects have a friction of 0.
let drag = jumpChangedDirections ? movementDrag : 0;
let desiredVelocity = (movementSpeed - drag) * movementDirection;
let change = desiredVelocity - currentVelocity.x;
let force = mass * change / (1 / 60); // 60hz
let walkingForce = Vec2(force, 0);
player.applyForceToCenter(walkingForce);
The mass
and currentVelocity
are just body#getter
shorthand variables for readability.
On most machines, everything runs perfectly and we good a smooth movement experience that looks something like this:
However, on the PCs that have this problem, whenever the user attempts to move (which calls the code above in testbed.step
they start to completely freak out.
We did some debugging remotely and I found that the cause of this issue seems to be over-compensation. Usually the value of change
is only adjusted when you are starting and stopping. However, in this example, change
gets set showing that the current x velocity is 1.8...
so it compensates for that with some force. (Our gravity is really heavy, by the way)
But then it seems to permenantly compensate back and forth and never find the sweet spot again of moving at movementSpeed
or standing still.
I’m really not sure what would cause this to happen, as most computers seem to have no problems running this simulation. I’ve done everything I can think of, but it’s a huge concern for my game.
Note: A force is usually only applied once during our movement, unless the direction is changed or the player stops moving. This force value is calculated to be 420 or -420 depending on direction, and 840/-840 when switching directions. For some reason, on this one computer, it’s being adjusted constantly. There’s no friction, just to double-clarify.
Note 2: Also a strange thing to notice, but the problem starts at a velocity of 1.8, but… in our application velocity is almost always 7, 0 or -7
(movementSpeed) or 3, 0, or -3
(movementSpeed - jumpDrag)
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
Yeah, that makes sense, that’s why I suspected
step
is the issue–currently step is called on each frame (rather than each physics step), while physic is called each 1/60 seconds, so with 180hz frame ratestep
is called 3 times more than it should. I will fix this issue.I changed script limit to 1M (it was 10K before).
@shakiba I’m going to be away for a few days, but I will send it off to be tested when I’m back.