• Create Account

### #ActualBacterius

Posted 10 October 2012 - 06:19 PM

Multiply the acceleration and velocity by your refresh rate (1.0 / 30.0 or 1.0 / 60.0), it'll be much smoother (since acceleration and velocity are defined with SI seconds, you need to take into account the number of times you update them every second). And get rid of the 0.1 multiplication, which looks like it's there as a band-aid.
[source lang="csharp"]public void accelerate(){for (int i = 0; i < 2; i++){ speed[i] += acceleration[i] * (1.0 / refreshRate); position[i] += speed[i] * (1.0 / refreshRate);}}[/source]
Look up Euler Time Integration for details, and you might have to swap around the velocity and position updates, not sure. Also deceleration is just negative acceleration, which you don't seem to be using here. It should work then.

If you need slightly slower deceleration, you can multiply your deceleration by any factor, like 0.5, and the ball will decelerate slower (because velocity will take more time to reach zero).

### #1Bacterius

Posted 10 October 2012 - 02:11 PM

Multiply the acceleration and velocity by your refresh rate (1.0 / 30.0 or 1.0 / 60.0), it'll be much smoother (since acceleration and velocity are defined with SI seconds, you need to take into account the number of times you update them every second). And get rid of the 0.1 multiplication, which looks like it's there as a band-aid.
[source lang="csharp"]public void accelerate(){for (int i = 0; i < 2; i++){ speed[i] += acceleration[i] * (1.0 / refreshRate); position[i] += speed[i] * (1.0 / refreshRate);}}[/source]
Look up Euler Time Integration for details, and you might have to swap around the velocity and position updates, not sure. Also deceleration is just negative acceleration, which you don't seem to be using here. It should work then.

PARTNERS