Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
There was once a game called Virtual Pool that relied on this exact mechanism to provide the user with some hints. The problem is that you need to use a bit of College Physics (inertia tensors) and, if you can, some continuous Physics update logic. I do believe that Virtual Pool relied on discrete updates and continuous collision detection.. spatial-temporal coherence was also a factor. Look-e here -> lsiit-cnrs.unistra.fr/Publications/2010/2-SBPJ10/… –  teodron Aug 1 '12 at 17:22
    
Related: gamedev.stackexchange.com/questions/7862/… –  Darcara Aug 1 '12 at 18:04
    
I'd probably be able to work out the math, but I was wondering if there's some kind of way to run it in memory, just without displaying it. For example simulate 100 update cycles without having to draw them, get the resulting location of the objects and use that... –  joon Aug 1 '12 at 21:21
2  
Jonathan Blow (of Braid fame) made a prototype of a similar sounding game he called Oracle Billiards (link) long ago. From what I recall, he didn't like what perfect knowledge did to the game of billiards, but that was just his opinion. His treatment might be worth checking out, though. –  chaosTechnician Aug 1 '12 at 23:53

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
1  
I found a way to do it in Box2d... I backup the current position and rotation of each ball, Apply the force and step the box2d world 100 times, draw the result, and revert back to the first state. works well and fast, since I'm not drawing on every Step of the world, but just in the end. –  joon Aug 3 '12 at 14:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.