well I sorted in the end thanks to all your help. This seems to work fine. The ball slingshots off nicely or goes into the hole. It uses some of my own classes but it should be obvious what they are doing:
Actually I haven't used the ball's speed to alter the force, merely it's distance from the centre but it seems to work fine anyway.
[EDIT] OK I added that in too for the hell of it and will now test at different speeds.
[EDIT]Problem with using the balls speed to modify the force. If it stops rolling over the edge it will just stay there so I added a gravity component to the force which is always there even if the ball is not moving.
'Is the ball teetering on the edge of the hole or in the hole? 'Remember Ball and Hole coords are midhandled. Local dist:TLine = TLine.Create(BallX,BallY,HoleX,HoleY) dist.CalcLength() If dist.Length<=HoleRadius Then 'Is the ball 100% in the hole? If dist.Length<=HoleRadius-BallRadius Then BallXSpeed=0 BallYSpeed=0 MinigameFadeOut.Start() 'Play a sound GameGrid.Channels.PlayGameSound(BallInHoleSound) InHole = 1 Else 'OK, the ball is teetering so deflect it's path towards the middle of the hole. 'This may not make it go in, it may skip over it. 'How much of the ball is over the hole minus the inner half that doesn't matter. Local OverHole:Double = HoleRadius-dist.Length 'Convert to a range of 0 to 1 Local tween:Double = OverHole/HoleRadius 'Make it fall in faster near the middle. tween = 1.0 - Cos(90.0*tween) 'Make a Vector pointing from the ball to the hole. Local Pull:TVector = TVector.CreateFromPoints(BallX,BallY,HoleX,HoleY) 'Make smaller Pull.Normalise() Local force! = 1.0 'tweak if need be pull.Scale(force*tween) BallXSpeed:+ pull.X*Delta BallYSpeed:+ pull.Y*Delta EndIf EndIf
Actually I haven't used the ball's speed to alter the force, merely it's distance from the centre but it seems to work fine anyway.
[EDIT] OK I added that in too for the hell of it and will now test at different speeds.
[EDIT]Problem with using the balls speed to modify the force. If it stops rolling over the edge it will just stay there so I added a gravity component to the force which is always there even if the ball is not moving.