Jump to content
  • Advertisement

Qweeg

Member
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Qweeg

  • Rank
    Newbie
  1. Qweeg

    Pool Cue Spin Physics

    Thanks Shadx, I think the main problem is my brainpower to be honest. I have managed to get something that works, but only in certain situations. Basically I have a clause that is executed the first time the cue ball collides (at the moment just with another ball not walls). This sets sidespin and a speed adjustment factor. Like this (the variables angleBetween and ang1 are as in the original post): ********************************************************************** if FirstCollision = 1 and x = 1 sidespin# = 100 velX1 = SIN(angleBetween+90 + sidespin#) * SIN(360-(angleBetween-ang1 - sidespin#))*vel1 velY1 = COS(angleBetween+90 + sidespin#) * SIN(360-(angleBetween-ang1 - sidespin#))*vel1 `-ve for topspin velX1 = velX1 * -0.9 velY1 = velY1 * -0.9 endif ********************************************************************** Now if the cue ball is coming from the left and strikes the object ball directly in the centre, the cue ball has topspin and slight sidespin and correctly rolls forward at a slight angle after impact. However if it strikes at a different angle things come out wrong. Or if the cue ball comes from the right or from above or below then things are wrong in some scenarios. The idea of the speed adjustment is that the more topspin or backspin on the cue ball the closer this adjustment will be to +/- 1. I guess I would need to consider the angle between the balls on impact and the direction the cue ball was travelling in. Since this is the first impact the object ball will be stationary. Then adjust how this calculation is done accordingly. The problem is I can't work out what needs to change when. Probably this introduction of sidespin into the equation is the wrong way to do it, but by trial and error I tried this and as it worked (albeit it in only a few scenarios).
  2. Qweeg

    Pool Cue Spin Physics

    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 ... ... ... *************************************
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!