Dr Brain wrote: |
You missed something. |
Code: Show/Hide int ballspeed(int initialspeed, int time) { while (time > 0) { int factor = min(initialspeed/1000 + 1, 4); if (time*factor > 1000) initialspeed -= 1000*friction; else initialspeed -= time*factor*friction; time -= 1000/factor; } return initialspeed; } |
Code: Show/Hide void UpdateBall()
{ ball.x += ball.xspeed; //kind of... gotta convert this from pixels/10seconds to pixels/Tick actually ball.y += ball.yspeed; //same here ball.xspeed -= (ball.xspeed/1000 + 1)*friction; ball.yspeed -= (ball.yspeed/1000 + 1)*friction; //Of course, it needs to check for bounces... if (Xcollision) ball.xspeed = -ball.xspeed; if (Ycollision) ball.yspeed = -ball.yspeed; } |
Code: Show/Hide Speed Time dTime/dSpeed 960 960 1 980 980 1 1000 1000 1 1020 1010 0,5 1040 1020 0,5 1060 1030 0,5 |
Samapico wrote: | |
|
Samapico wrote: |
So for now I'm only working with friction=1. |
Quote: |
2500 / 30 = 83 (I know this is lower than the actual figure if you calculate all the iterations, but it gives a ball park figure)
Looking at approx 1 second for the ball to stop using that formula. However you can see in cont it actually takes around 7 seconds for the ball to stop. |
Smong wrote: |
[..]
I think you should be looking at a range of frictions. I don't know if you can assume friction=2 is the same as "apply the friction=1 code twice as often". |
Quote: |
A possibility would be that sqrt(fraction) would be part of the formula... |
Code: Show/Hide Init.Speed Dist Airtime 2000 1251 15000 2060 1288 15100 |
Doc Flabby wrote: |
Does PSpace ever work out the ball friction? |
Code: Show/Hide fireball()
{ ball.frictiontimer = 1000000; } // call this per tick updateball() { if (ball.xspeed || ball.yspeed) { int workfriction = ball.frictiontimer / 1000; ball.xspeed = ball.xspeed * workfriction / 1000; ball.yspeed = ball.yspeed * workfriction / 1000; ball.frictiontimer -= cfg_friction; if (ball.frictiontimer < 0) ball.frictiontimer = 0; } } |