Thursday, February 15, 2018

mathematics - Predicting physics/trajectory for pool/billiards games


I'm thinking of making a quick proof of concept of a billiard-style game mechanic, where the player has perfect information of what is about to happen. Here's a good example:


enter image description here


I'm only mildly familiar with physics in both Unity and Flixel-Box2D, and I can't really off the top of my head imagine how to do this.


Should I even use physics at all, or should I just use basic math?



Answer



To generate those lines you need to run the complete simulation of the whole shot every frame, as if you'd just hit the cue ball. This requires keeping two copies of the table state - one for display and one for simulation. For each frame of the simulation you just store the position of each ball, and at the end use that data to draw lines with. This simulation wants to happen quickly enough to maintain an interactive frame rate, although you can work round spikes in compute time with a thread.


The physics for a basic 2D simulation aren't too complicated if you don't care too much about accurately simulating a real pool table. It gets significantly harder to simulate it well when you take in to account jump shots and swerve shots as the balls can then move along curves instead of straight lines. The shot where you break the pack is also difficult to simulate correctly as there are going to be lots of touching, or almost-touching balls, which may trip up a physics simulation.



I'd suggest trying out a few physics libraries to see which one gives you the best results. Setting up a box full of spheres and hitting one of them should be fairly simple in any decent physics engine.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...