I’m having trouble with some physics code. When the user presses an arrow key, it adds/subtracts 0.25 to the character’s x velocity. Then the world steps, which should add/subtract 0.05 to get it closer to 0. This output of the velocity for each step shows what went wrong:
0.0 //Not moving
0.25 //Pushed arrow key
0.45 //Held arrow key some more + game subtracted 0.05
0.4 //Subtracted 0.05
0.35000000000000003 //Subtracted 0.05
0.30000000000000004
0.25000000000000006
0.45000000000000007 //added 25, subtracted 0.04
0.4000000000000001
This gets things confused and the character will keep creeping along slowly in the same direction, while going through things it would normally collide with.
What might be wrong?
Rounding to 2 decimal places would work, but I want to see if there is a better way first.
When I jump, sometimes my feet get stuck in the ground, I’m assuming that’s a related problem.
