- #1
DarkBabylon
- 72
- 10
Hello, I have been working on a little movement system in a program called Game Maker: studio.
The code works fine on the programming perspective, but something I did not expect happened:
When I ran the code by adding to the speed while pressing a key, and every step passively subtracting from the speed I got a certain number I did not expect to find.
Essentially the code run like this:
if key=pressed {speed+=2};
speed-=0.25*speed;
Which according to the game maker syntax should add to the speed while the key is pressed by 2 pixels per step, and afterwards it will subtract from the speed what would be equal a quarter of the speed previously calculated.
With this method I got top speed of 6 pixels per step.
However when I just put out the entire differential equation under the key press 'if' statement, it returned a top speed of 8 pixels per step, which was exactly as an analytical analysis would predict.
Question is, why is it so? Can't seem to get why would that matter at least not at hindsight.
The code works fine on the programming perspective, but something I did not expect happened:
When I ran the code by adding to the speed while pressing a key, and every step passively subtracting from the speed I got a certain number I did not expect to find.
Essentially the code run like this:
if key=pressed {speed+=2};
speed-=0.25*speed;
Which according to the game maker syntax should add to the speed while the key is pressed by 2 pixels per step, and afterwards it will subtract from the speed what would be equal a quarter of the speed previously calculated.
With this method I got top speed of 6 pixels per step.
However when I just put out the entire differential equation under the key press 'if' statement, it returned a top speed of 8 pixels per step, which was exactly as an analytical analysis would predict.
Question is, why is it so? Can't seem to get why would that matter at least not at hindsight.