# Looking For A "Billiards/Pool" Tutorial

15 replies to this topic

### #1 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 30 March 2013 - 12:43 PM

Hello GMC!

I've been looking around for a tutorial on making the physics needed for a pool game. I've found a few leads but nothing that suits me. I found this video on youtube:

But this guy doesn't quite seem to know what he's doing. Also the scripts were not very compatible with GM: Studio.

I also found a post here on the forums containing a tutorial for this but all the links were broken.

Anyone got any ideas? Anyone got an old billiards game source code lying around that I could take a look at?

Best wishes!

• 0

### #2 MartinD

MartinD

GMC Member

• GMC Member
• 148 posts
• Version:GM8

Posted 30 March 2013 - 01:04 PM

Most people are willing to help you with the coding but I dont think anyone is really willing to give away an entire project. If you can tell me what part of the coding you find hard to do, I could help you with it

• 0

I like to help everyone out. If I do succeed, could you also help me out by just voting up my post? I would highly appreciate that

### #3 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 30 March 2013 - 01:27 PM

I'm not looking for someone to give away an entire project. Perhaps I should have been more informative.

What I'm looking for is simply to be pointed in the right direction. I've had a look around and this is what I've found so far:

```with (obj_collisionsphere)
{
if (other.id!=id)
{
// check if other balls are in collision distance
dist = point_distance(x,y,other.x,other.y)
// move balls outside of each other if they are intersecting
if (intersect >= 0)
{
x += lengthdir_x(intersect/2,point_direction(other.x,other.y,x,y))
y += lengthdir_y(intersect/2,point_direction(other.x,other.y,x,y))
other.x += lengthdir_x(intersect/2,point_direction(x,y,other.x,other.y))
other.y += lengthdir_y(intersect/2,point_direction(x,y,other.x,other.y))

// implementation of found physics formulas
v1xx = xx * x1;
v1xy = xy * x1;
v1yx = velx - v1xx;
v1yy = vely - v1xy;

xx *= -1;
xy *= -1;
v2xx = xx * x2;
v2xy = xy * x2;
v2yx = other.velx - v2xx;
v2yy = other.vely - v2xy;

tmass = mass;
other.tmass = other.mass;
if (tmass <= 0) { tmass = 1000000; }
if (other.tmass <= 0) { other.tmass = 1000000; }

if (mass > 0)
{
velx = v1xx*(tmass-other.tmass)/(tmass+other.tmass) + v2xx*(2*other.tmass)/(tmass+other.tmass) +v1yx
vely = v1xy*(tmass-other.tmass)/(tmass+other.tmass) + v2xy*(2*other.tmass)/(tmass+other.tmass) +v1yy
}

if (other.mass > 0)
{
other.velx = v1xx*(2*tmass)/(tmass+other.tmass) + v2xx*(other.tmass-tmass)/(tmass+other.tmass) +v2yx
other.vely = v1xy*(2*tmass)/(tmass+other.tmass) + v2xy*(other.tmass-tmass)/(tmass+other.tmass) +v2yy
}

}

}
}
```

Courtesy of Jake Armstrong

I understand some of this but I'm having trouble implementing it. I've declared all the variables needed but I'm not sure what I should do with the velocity variables (velx and vely). I've parented obj_ball to obj_collisionsphere and they share the same size. The balls are 64x64px big so the rad variable is 32. The mass variable I had no idea what to do with so I simply set it to 1.

With a little bit of work I managed to get the balls to move with the mouse when "selected". With this I could see if the collision worked properly and it did. So now my only problem is how to get the "shot" to work. How to get the balls moving.

Any ideas?

My apologies if I sound clueless. It's because I am.

Edited by milo-rd, 30 March 2013 - 01:29 PM.

• 0

### #4 MartinD

MartinD

GMC Member

• GMC Member
• 148 posts
• Version:GM8

Posted 30 March 2013 - 02:04 PM

• 0

I like to help everyone out. If I do succeed, could you also help me out by just voting up my post? I would highly appreciate that

### #5 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 31 March 2013 - 12:51 PM

Thanks for this! Giving this a try today!

• 0

### #6 MartinD

MartinD

GMC Member

• GMC Member
• 148 posts
• Version:GM8

Posted 31 March 2013 - 07:19 PM

No problem, let me know if it worked

• 0

I like to help everyone out. If I do succeed, could you also help me out by just voting up my post? I would highly appreciate that

### #7 van0014

van0014

GMC Member

• GMC Member
• 301 posts
• Version:GM8.1

Posted 01 April 2013 - 07:27 AM

This is a half-decent basis to work from, made from MartinD's example

• 1

Proud user of GM 8.1

### #8 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 01 April 2013 - 08:39 AM

Woah!

Thank you so much, Martin & Van0014! This has helped me tremendously. Took some time to work out the quirks (totally different ways of declaring and reading global variables, I guess) in the .gmk. I got it to work!

This seems to be a great and helpful community. Looks like I'm going to enjoy my stay.

Happy easter guys!

• 0

### #9 MartinD

MartinD

GMC Member

• GMC Member
• 148 posts
• Version:GM8

Posted 01 April 2013 - 11:49 AM

No problem! And also have a nice easter yourself

• 1

I like to help everyone out. If I do succeed, could you also help me out by just voting up my post? I would highly appreciate that

### #10 van0014

van0014

GMC Member

• GMC Member
• 301 posts
• Version:GM8.1

Posted 03 April 2013 - 04:10 AM

I updated the little example i had. Ive managed to find code to handle the physics properly.

When a ball hits another ball head on, the first ball will nearly stop moving, and the other will take off.

• 0

Proud user of GM 8.1

### #11 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 04 April 2013 - 08:30 PM

Wow, awesome! Thanks a lot, Van!

I'll keep you posted and let you know how this all turns out.

Have a good one!

• 0

### #12 icuurd12b42

icuurd12b42

Self Formed Sentient

• GMC Elder
• 18181 posts
• Version:GM:Studio

Posted 04 April 2013 - 09:00 PM

You can also check my Learning From Scratch Pool Table Tutorial... in my tools page.

If you are using Studio, the process should be much simple for the bouncing...

• 0

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button

### #13 van0014

van0014

GMC Member

• GMC Member
• 301 posts
• Version:GM8.1

Posted 05 April 2013 - 05:17 AM

Its brilliant. icuurd has made a huge tutorial for pool games. You should check it out.

Covers everything, from physics to top-down 3D for realistic ball rolling.

• 0

Proud user of GM 8.1

### #14 milo-rd

milo-rd

GMC Member

• New Member
• 7 posts
• Version:GM:Studio

Posted 05 April 2013 - 10:55 AM

Sweet! This gives me an excuse to poke around with some 3D too! :D

• 0

### #15 shamik3

shamik3

GMC Member

• New Member
• 5 posts
• Version:GM:Studio

Posted 03 July 2014 - 10:53 AM

• 0

### #16 icuurd12b42

icuurd12b42

Self Formed Sentient

• GMC Elder
• 18181 posts
• Version:GM:Studio

Posted 03 July 2014 - 05:33 PM