Pool(Billiards) physics (Need help)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
betobala
Prole
Posts: 11
Joined: Sun May 19, 2024 11:37 pm

Pool(Billiards) physics (Need help)

Post by betobala »

Hello everyone, I'm a beginner game developer, trying to make my first game. My idea is based on billiards physics, but I don't have a clue how to make it. Can I get any suggestions on what I should study or any library that could help me with that?
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Pool(Billiards) physics (Need help)

Post by pgimeno »

Well, it depends on the degree of sophistication you're after.

If you just want basic bounces, without considering aspects like friction with the cushions or during ball collisions, or whether the ball is hit off-centre to give it a spinning efect, then you could do with a simple bouncing-based scheme which only requires a bit of vector math and very little trigonometry, if any.

If you are after an accurate simulation of effects, frictions during impacts, etc. then you're better off studying dynamics in detail, because there's a lot involved there.

The middle compromise is probably to use the love.physics module, which will not give you a very accurate simulation, but it will be able to include bouncing, cushion friction and (2D) rotational momentum without you worrying about implementing them yourself.
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Pool(Billiards) physics (Need help)

Post by dusoft »

Just use the love.physics module while setting gravitation to 0. That should work.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Pool(Billiards) physics (Need help)

Post by pgimeno »

Here's a PoC of the love.physics approach. Lots of magic numbers everywhere as I fine-tuned the parameters by trial-and-error, sorry.

As I feared, love.physics doesn't do bouncing too well, and balls sometimes stick to the cushions if they are very slow, even when setting restitution to 1.
Attachments
lovePhysicsPool.love
(1.49 KiB) Downloaded 191 times
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Pool(Billiards) physics (Need help)

Post by BrotSagtMist »

This is already cooler than 90% of what you find in comercial pool games for old consoles.

The problem here is that this kind of game is all about physics, you gotta have to nail it or else its garbage.
So pool is not the smartest starting point to get into game dev.
obey
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Pool(Billiards) physics (Need help)

Post by dusoft »

BrotSagtMist wrote: Mon May 20, 2024 6:44 pm This is already cooler than 90% of what you find in comercial pool games for old consoles.

The problem here is that this kind of game is all about physics, you gotta have to nail it or else its garbage.
So pool is not the smartest starting point to get into game dev.
Anything with complex physics is not suitable as a beginner's project. Although having libraries (or API such love.physics), to make it easier, helps.
betobala
Prole
Posts: 11
Joined: Sun May 19, 2024 11:37 pm

Re: Pool(Billiards) physics (Need help)

Post by betobala »

Thanks all, that helped me a lot!
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Pool(Billiards) physics (Need help)

Post by darkfrei »

I've made small example with circles collision detection and static/dynamic resolving: viewtopic.php?p=240339#p240339

Two main collision functions:

Code: Select all

function pushback (collision)
	local particles = collision.particles
	local b1, b2 = particles[1], particles[2]
	local overlap = collision.overlap
	local nx, ny = collision.nx, collision.ny 
	b1.x = b1.x - nx*overlap
	b2.x = b2.x + nx*overlap
	b1.y = b1.y - ny*overlap
	b2.y = b2.y + ny*overlap
end

Code: Select all

function rollback (collision)
	local particles = collision.particles
	local b1, b2 = particles[1], particles[2]
	local nx, ny = collision.nx, collision.ny -- normal
	local tx, ty = -ny, nx -- tangent
	
	local dptan1 = b1.vx*tx + b1.vy*ty
	local dptan2 = b2.vx*tx + b2.vy*ty
	
	local dpnorm1 = b1.vx*nx + b1.vy*ny
	local dpnorm2 = b2.vx*nx + b2.vy*ny
	
	local m1 = (dpnorm1*(b1.mass-b2.mass)+2*b2.mass*dpnorm2)/(b1.mass+b2.mass)
	local m2 = (dpnorm2*(b2.mass-b1.mass)+2*b1.mass*dpnorm1)/(b1.mass+b2.mass)
	
	b1.vx = tx*dptan1 + nx*m1
	b1.vy = ty*dptan1 + ny*m1
	b2.vx = tx*dptan2 + nx*m2
	b2.vy = ty*dptan2 + ny*m2
end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest