Billiards, precision, and i need advice...

hi...

i guess i should ask for some advice before going all-out on a mad solution... 😕

i'm building a multiplayer billiards game, and have run into a couple of problems...

while creating the AI for single-player mode, i found that balls don't really travel where they are mathematically supposed to... after some testing, i concluded this is due to the subtle difference in contact points between what's expected by the AI and what the engine gets as it iterates in discrete steps...


you see, the AI is programmed to shoot for an "ideal" target, but as the ball gets there, there's no guarantee that the collision will be registered at that precise point, since it'll most likely fall between steps 🤓


this also led to a larger problem... while i could simply have the AI "cheat" the targeted ball to correct for this, in multiplayer, it'll simply not do...
how can i expect a game to flow nicely, if i'm unable to have matching results on two different machines?

i ran a few controlled tests just to notice that under the same conditions in two separate runs - the results are DIFFERENT 😮 😮 😕 🙁


ok, then i figure... 🤓 -> *mad scientist mode - activate!* -> 🤓

i'll use a raycast to find the first collision, then "load" the targeted ball with the expected results, then proceed into recursively repeating this for every ball hit by the current one, untill the "energy" runs out (balls stop)... all this before actually shooting the cue ball... then, the balls, now loaded with the direction they should go when struck, can correct themselves when they actually collide...

this leads to an even bigger problem... this method assumes every ball hit is stopped... hence, calculating ahead is due, i'd have to take the expected direction of each ball set in motion and use line intersection to determine a possible moment of impact based of the projected velocity of both balls involved in each intersection

(am i still making sense?)

so before i venture out into the jungle of my own madness... IS THERE A BETTER WAY?


any advice is welcome - anything more relevant than "look both ways before crossing the street" will do 🙄


thanks in advance!
box2d is said not to be ideal for multiplayer.

Billiards should be more forgiving of a multiplayer game, since users take turns. rather than all interacting at once.

this means that you could correct position, direction, and speed for each ball at certain time intervals using the data from the machine who's turn it is.

that does not help you perfect your AI, for that i recommend:
A: cheat like you said
B: reprogram your AI to think in time steps some how.
C: accept and rejoice that your AI has some amount of random error built in, so that computer opponents are a bit more "human".
D: a way to decrease the margin of error, add more timesteps.

hope this helps some. i personally stick to single player games as much as i can.
CCD may help, because it interpolates collision points between times steps. Set bullet = true on your billiard ball body defs. According to this post:

viewtopic.php?f=2&t=3201

it should work perfectly for ball-ball collisions, but not necessarily ball-wall collisions (you may be able to fix this by offsetting your physics walls from your AI walls and rendered walls by the skin thickness.)
CCD does help, i was using it before...

still, no matter how much i crank up the iterations, there's a large error, which makes for very difficult targeting, for both AI and player...


then i guess i'm stuck with forcing corrections, ok... i can do it -i hope- let's see how it goes...
i think posing the question as accuracy of billiard collision angles, without the multi-player aspect, would get the attention of BorrisTheBrave or Erin Catto who may be able to make better suggestions on how to get the accurate results you desire.

Original thread: https://box2d.org/forum/viewtopic.php?t=5075