Original Post
Could someone help please? I am currently working on a 2D pool game using a product called Dark Basic. I have the basic game working and the general motion and collisions seem fine. The problem is I now want to account for spin (english). Since it is a 2D game I have really just used Trig to calculate the motion, rather than more complex vector physics. Really what I want is something that plays well, without necessarily being a true physics simulation. So I guess my question is - is there a simple way I can adjust the motion of the cue ball when it collides, to account for the spin on it. Below is a simplified section of the code, with comments that hopefully make sense. To keep it simple I was kind of thinking that maybe I could just consider what happens to the cue ball when it first collides, ignoring the effects on other balls. Note that the code below doesn't include the section for Wall collision (I thought it would make this already long post far too much). Any help would be greatly appreciated ************************************* FirstCollision = 1
Do the movement of the balls and collision detection in steps, for increased accuracy FOR l=1 TO numSteps set to 30 Loop through all balls 1=cueball FOR x=1 TO numBalls Move the ball INC balls(x).xPos,balls(x).xVel/numSteps INC balls(x).yPos,balls(x).yVel/numSteps Control the shooting of the ball ... ... ... shotAng = 360-(180-ATANFULL(mouseHoldX-MOUSEX(),mouseHoldY-MOUSEY())) shotpower = 10 constant for testing purposes balls(1).xVel=SIN(shotAng)*shotPower balls(1).yVel=COS(shotAng)*shotPower Loop through all balls FOR y=1 TO numBalls Don't check collision between the same ball IF y<>x Get distance of balls from each other dist = SQRT((balls(x).xPos-balls(y).xPos)^2+(balls(x).yPos-balls(y).yPos)^2) If they are touching IF dist < ballRad*2 Get the angle between them angleBetween = ATANFULL(balls(x).xPos-balls(y).xPos,balls(x).yPos-balls(y).yPos) Move the first ball back where it was DEC balls(x).xPos,balls(x).xVel/numSteps DEC balls(x).yPos,balls(x).yVel/numSteps Get the angles of the balls velocities ang1 = ATANFULL(balls(x).xVel,balls(x).yVel) ang2 = ATANFULL(balls(y).xVel,balls(y).yVel) Get the speed of the balls velocities, with a slowing factor vel1 = SQRT(balls(x).xVel^2+balls(x).yVel^2)*0.9 vel2 = SQRT(balls(y).xVel^2+balls(y).yVel^2)*0.9 Work out the new velocities of the balls using trig velX2 = SIN(angleBetween)*COS(angleBetween-ang1)*vel1 + SIN(angleBetween+90)*SIN(360-(angleBetween-ang2))*vel2 velY2 = COS(angleBetween)*COS(angleBetween-ang1)*vel1 + COS(angleBetween+90)*SIN(360-(angleBetween-ang2))*vel2 velX1 = SIN(angleBetween+90)*SIN(360-(angleBetween-ang1))*vel1 + SIN(angleBetween)*COS(angleBetween-ang2)*vel2 velY1 = COS(angleBetween+90)*SIN(360-(angleBetween-ang1))*vel1 + COS(angleBetween)*COS(angleBetween-ang2)*vel2 ****/ IF THIS IS THE FIRST COLLISION OF THE CUE BALL CHECK ALTER THE POST COLLISON DIRECT/SPEED ACCORDING TO SPIN ON THE CUE BALL HERE IS WHERE THE PROBLEM IS ****/ if FirstCollision = 1 and x = 1 FirstCollision = 0 endif `Set the balls' velocities balls(x).xVel = velX1 balls(x).yVel = velY1 balls(y).xVel = velX2 balls(y).yVel = velY2 ... ... ... *************************************