Server Help

ASSS Questions - Ball friction (that time of year again?)

Samapico - Wed Mar 05, 2008 10:13 am
Post subject:
Split by Smong at March 6, 2008, 9:38 am

ball friction formula eh...

brb icon_wink.gif
tcsoccerman - Wed Mar 05, 2008 4:11 pm
Post subject:
i suppose you wouldn't need the formula if you were recording. just wait until the next frame to display the powerball position. or did i miss something?
Dr Brain - Wed Mar 05, 2008 4:31 pm
Post subject:
You missed something.
tcsoccerman - Wed Mar 05, 2008 4:58 pm
Post subject:
ok.
Samapico - Wed Mar 05, 2008 5:02 pm
Post subject:
Dr Brain wrote:
You missed something.
lol


Did anyone made real attempts to figure out that ball formula?
With some modifications on Bak's auto-fighting bot, I believe I could make it follow the ball on radar, and then I could get values of position vs time. Try that with different friction values, pull out some equations, and solve... Could throw out a few different equation forms, and see which one fits the best. If it's not linear, the most probable thing is an exponential, which could be solved from a differential equation (i.e. loss of speed is proportional to speed, much like the air resistance when something falls down).

If I'm wasting my time and this has already been tried, tell me... But I never read anything about that, so...
Bak - Wed Mar 05, 2008 8:20 pm
Post subject:
it's not linear and it's not exponential. Arnk has a nice spreadsheet floating around somewhere, or if you look in really old topics you'll see some of my spreadsheets.

using the pixel radar thing won't be very accurate since that bot only gets a few frames/second not to mention the radar is very coarse.

samapico, i'd say go for it, and if you succeed you will have trumped us all proving that you are the superior human being
Samapico - Wed Mar 05, 2008 9:03 pm
Post subject:
well, I thought maybe with a good radar zoom factor, it could be relatively accurate...

I'll try to find these spreadsheets tongue.gif
Bak - Wed Mar 05, 2008 10:44 pm
Post subject:
http://rshl.org/akd/balls.xls
Samapico - Wed Mar 05, 2008 11:51 pm
Post subject:
whoah... it really is a step function :/
fecking weird
Samapico - Thu Mar 06, 2008 1:12 am
Post subject:
ok...

in 1 millisecond, speed is reduced by [something that depends on speed]:

newspeed -= (currentspeed/1000)+1

currentspeed/1000 + 1 cannot be larger than 4 apparently


Here's something that 'could' maybe work..didn't test it or anything yet
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;
}


(feel free to split this whole ball thing topic if needed)


it doesn't really work how I want it to.. but anyway.. the idea is to take away the speed , 1000 units at a time. And "use" a part of the time each time. Taking away 1000 units of speed between 3000 and 4000 "uses" less time than between 2000 and 3000...
I'm kinda tired so my brain can't properly code that...
In theory, if you put that in Bak's excel, and ask for the newspeed of every initialspeed with a time of (the time given), it should give close to 0 for all of them

Also, it's probably possible to simplify it a lot tongue.gif I don't really think Priitk would have cared to make a while loop for that kind of thing tongue.gif Could probably be done with a single substraction
Smong - Thu Mar 06, 2008 12:50 pm
Post subject:
Here's one of the older threads:
http://forums.minegoboom.com/viewtopic.php?t=2747

On page 2 there's a claim the formula is found. But there's 2 more pages arguing over it.
Samapico - Thu Mar 06, 2008 3:15 pm
Post subject:
I didn't see any realistic formula in there... just theories based on 1 or 2 numbers tongue.gif

The formula above is very ugly... however, if the speed if modified every tick, then it's pretty easy:

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;
}


This is still a theory, since I only had the data for friction = 1... Bak, do you still have that module that made you get those values in your excel sheet? Could it be re-done for different friction values? And possibly with even more ball speed... The fact that the ball doesn't behave the same over 4000 is intriguing me; I'd like to see what happens with very high speeds.
Basically, the faster the ball is, the more speed it loses

Would be nice to have a way to compare a model with the real thing too. Like the module could drop mines following the path of the model at the same time as the real ball travels.



It's quite simple to come to this conclusion with the data Bak posted

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

We can see that the ball takes 10 ticks to go from 1020 to 1000 speed, and then it takes 20 ticks for 20 speed units all the way to 0.
The exact same thing happens every 1000 speed. Except after 3000 it seems to be a constant 4 <speedunits> / millisecond

One question though... if all values are integers, how would a ball of speed=1 move if (speed/1000) is added every millisecond (or /100 if a tick is 1/100th of second).

EDIT: I wrote milliseconds almost everywhere... just realised they were hundreths of seconds icon_sad.gif
Samapico - Thu Mar 06, 2008 4:01 pm
Post subject:
EDIT2:

Seems like there is no "limit" on the "ballspeed/1000" thing actually...

Just threw a ball with 20000 speed, and it seems to match the model I put up above. With speed being reduced of 20 every tick between 19000 and 20000.
Smong - Fri Mar 07, 2008 3:18 pm
Post subject:
Samapico wrote:
Code: Show/Hide
void UpdateBall()
   ball.xspeed -= (ball.xspeed/1000 + 1)*friction;
   ball.yspeed -= (ball.yspeed/1000 + 1)*friction;
}

This will make the ball eventually travel up and left. And your + doesn't take into account if the ball speed is positive/negative.

Also isn't it nicer to say something like "friction + (ball.xspeed * friction) / 1000", that way you avoid integer rounding errors.

----

Very rough calculations on "(ball.xspeed/1000 + 1)*friction"
Default svs: friction = 12, ball fire speed = 2500
Assume ship is stationary and not facing a diagonal direction.

2500 / 1000 * 12 = 30 (ignoring the + 1 for now)
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.

----

Also looking at my rearranged form:
(ball.xspeed/1000 + 1)*friction -> friction + (ball.xspeed * friction) / 1000
You can see it cannot work because you are always applying a minimum of friction, which if it was 12 and applied at 100 times a second thats 1200. Imagine a 2500 speed ball, 2500 - 1200 = 800, max(800 - 1200, 0) = 0 the ball would stop dead in less than 2 seconds instead of gradually slowing to a stop.

Edit: more disproving.
Samapico - Fri Mar 07, 2008 4:55 pm
Post subject:
Yeah I noticed several mistakes in what I posted above too tongue.gif I never said it was really working either; Was just throwing out what I found out.

The *friction are very theoric too, since I only used the data with a friction = 1, so I have no idea what in the equation will change with different friction values... So for now I'm only working with friction=1. A possibility would be that sqrt(fraction) would be part of the formula...

Also, the function dSpeed/dT is clearly in steps... However, it's not 1,2,3,4 as I said before. I was kind of tired when I wrote that...
Speed ; dS/dT

[ 0 ; 1000] ; 1
[1000, 2000] ; 2
[2000, 3000] ; 6
[3000, 4000] ; 8
[4000, 5000] ; seems to average at 8 too
[5000, ... ] ; no data, but I'm pretty sure it goes higher than 8

...Can anyone figure out some kind of series that can do 1,2,6,8 ?? (and ideally, 1,2,6,8,8 )
Smong - Fri Mar 07, 2008 5:11 pm
Post subject:
Samapico wrote:
So for now I'm only working with friction=1.
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".
Samapico - Fri Mar 07, 2008 5:20 pm
Post subject:
Also, when I write ballspeed/1000, I assume integer divisions. For example, 2999/1000 = 2. That's how C++ does it (by default).

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.
You must understand that as the ball slows down, the loss of speed will also decrease. And as I said in the above post, the formula wouldn't really look like that anyway
Samapico - Fri Mar 07, 2008 5:20 pm
Post subject:
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...

Got to make the formula work with a friction of 1 first...
Samapico - Fri Mar 07, 2008 6:31 pm
Post subject:
So far, it seems to work relatively well with the airtime... i.e. the time before the ball reaches a speed of 0. However, there is something I don't understand in the distance travelled...


Code: Show/Hide

Init.Speed    Dist  Airtime
2000          1251  15000
2060          1288  15100

Speed is in px/10s, Distance is in px, Airtime is in ms.

If you travel at 2060 px/10s during 100ms, you should travel a total of:
2060/10000 * 100 = 20.6 pixels.
Right? Divide by 10000 to get pixels per milliseconds, then multiply by the number of milliseconds. (It would be a bit less, because speed goes down from 2060 to 2000 during that time, but let's forget about that).

However, in Bak's data, the additionnal 100ms of flying at ~2060speed added 37 pixels... Almost twice as much as expected. WTF?
The same thing happens throughout the whole data... Because of this, the distance travelled shown by my simulator is always much lower than in the datasheet.
However, I'm assuming that a ball fired at 2060 will act the same as a ball fired at 2000 once it reaches the speed of 2000. This shouldn't be a problem, unless the formula includes something about the InitialSpeed. It would be very surprising and stupid, but... :/
Is there anything I don't understand in the relation between speed and distance? I mean... it should work like a simple ship right?


Here's Bak datasheet with some comments and additional calculated data
Bak - Fri Mar 07, 2008 10:19 pm
Post subject:
in case the "akd" in the url wasn't a give-away, that's arnk's data sheet so you'll have to bug him for the module (although I did make quite a few bots to measure it when I was after this grail)
Samapico - Fri Mar 07, 2008 11:04 pm
Post subject:
oh... lol thought it was all yours tongue.gif sorry
Smong - Sun Mar 09, 2008 12:11 pm
Post subject:
http://www.youtube.com/watch?v=eoICmuwghDQ $$
Doc Flabby - Sun Mar 09, 2008 12:17 pm
Post subject:
Does PSpace ever work out the ball friction?
Samapico - Sun Mar 09, 2008 12:17 pm
Post subject:
Pretty much the same problem as me it seems... the deceleration takes the same time, but less distance is travelled
Smong - Sun Mar 09, 2008 12:19 pm
Post subject:
Doc Flabby wrote:
Does PSpace ever work out the ball friction?
No I checked that. There is some commented out code that applies friction as a percentage of the current speed.
Doc Flabby - Sun Mar 09, 2008 12:22 pm
Post subject:
Does anyone know if the ball friction formula unique to continuum, or is it identical to the subspace one? Also at what version of continuum was the ball friction finalised? It may be worthwhile trying to rip the assembly of it, especially now as tool have been provided by snrruub to unpack the (older versions of) continuum exe.
Smong - Sun Mar 09, 2008 12:32 pm
Post subject:
I think cont has it the same or very close. It would have been in 36 since that was in use at the same time as 134/135 so they would have to at least appear to be the same.

I just tweaked my code a bit and now it's coming out within 5px of cont. Only problem is some of the collision code doesn't match exactly, so in that circle in smallmap where there are a lot of corners it occasionally bounces wrong.

Edit1: Ok I'm pretty sure about this now:
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;
   }
}


Edit2: fixed typo.
Edit3: fixed typo.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group