Jump to content


Photo

Looking For A "Billiards/Pool" Tutorial


  • Please log in to reply
15 replies to this topic

#1 milo-rd

milo-rd

    GMC Member

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

Posted 30 March 2013 - 12:29 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:

 

https://www.youtube....h?v=Ff3UVtI-r-A

 

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
  • 145 posts
  • Version:GM8

Posted 30 March 2013 - 12:50 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

#3 milo-rd

milo-rd

    GMC Member

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

Posted 30 March 2013 - 01:13 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)
        intersect = rad+other.rad-dist
        // 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))
            xx = (x-other.x)/(rad+other.rad);
            xy = (y-other.y)/(rad+other.rad);
            
            // implementation of found physics formulas
            x1 = point_distance(0,0,velx,vely)*cos(degtorad(abs(point_direction(0,0,xx,xy)-point_direction(0,0,velx,vely))))
            v1xx = xx * x1;
            v1xy = xy * x1;
            v1yx = velx - v1xx;
            v1yy = vely - v1xy;
            
            xx *= -1;
            xy *= -1;
            x2 = point_distance(0,0,other.velx,other.vely)*cos(degtorad(abs(point_direction(0,0,xx,xy)-point_direction(0,0,other.velx,other.vely))))
            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. :P


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

  • 0

#4 MartinD

MartinD

    GMC Member

  • GMC Member
  • 145 posts
  • Version:GM8

Posted 30 March 2013 - 01:50 PM

Try this:

 

https://www.dropbox....ipy/Snooker.gmk


  • 0

#5 milo-rd

milo-rd

    GMC Member

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

Posted 31 March 2013 - 12:37 PM

Thanks for this! Giving this a try today!


  • 0

#6 MartinD

MartinD

    GMC Member

  • GMC Member
  • 145 posts
  • Version:GM8

Posted 31 March 2013 - 07:05 PM

No problem, let me know if it worked :)


  • 0

#7 van0014

van0014

    GMC Member

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

Posted 01 April 2013 - 07:13 AM

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

 

http://www.upurload....3a3bcf701f9.gmk


  • 1

#8 milo-rd

milo-rd

    GMC Member

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

Posted 01 April 2013 - 08:25 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
  • 145 posts
  • Version:GM8

Posted 01 April 2013 - 11:35 AM

No problem! And also have a nice easter yourself :thumbsup:


  • 1

#10 van0014

van0014

    GMC Member

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

Posted 03 April 2013 - 03:56 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.

 

4fb981ef34f6bc7c4d1fa55424e96a3f.png


  • 0

#11 milo-rd

milo-rd

    GMC Member

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

Posted 04 April 2013 - 08:16 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
  • 16041 posts
  • Version:GM:Studio

Posted 04 April 2013 - 08:46 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

#13 van0014

van0014

    GMC Member

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

Posted 05 April 2013 - 05:03 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

#14 milo-rd

milo-rd

    GMC Member

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

Posted 05 April 2013 - 10:41 AM

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


  • 0

#15 shamik3

shamik3

    GMC Member

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

Posted 03 July 2014 - 10:39 AM

All the gmk links are dead ... If you could reupload it would be of big help !! Thanks in Advance !  :thanks:


  • 0

#16 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 03 July 2014 - 05:19 PM

All the gmk links are dead ... If you could reupload it would be of big help !! Thanks in Advance !  :thanks:

Look 2 post above yours
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users