# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### DarkBASIC Discussion / My collsions suck.... - HELP!!!

Message
Posted: 27th Nov 2002 23:26
Hello again...
How come on this code, the ball and the cube penetrate each other sometimes?
How can I avoid that????
I think it has to do with repositionning the ball after the collision test, but I am not sure.
HELP!!!

Da code:

sync on
sync rate 0

`create matrix
make matrix 1,600,600,10,10
position matrix 1,0,0,0

`camera settings
autocam off
position camera 300,500,-150
point camera 300,0,300

`create object
make object sphere 1,60
set object collision to boxes 1
make object cube 2,40
set object collision to boxes 2

`variables
BallStepX=4
BallStepZ=4
BallXposition = 393
BallZposition = 248
CubeStepX=8
CubeXposition = 300
do
`previous positions
PrevBallXposition=BallXposition
PrevBallZposition=BallZposition

`increments
BallXposition = BallXposition + BallStepX
BallZposition = BallZposition + BallStepZ
CubeXposition = CubeXposition + CubeStepX

`update positions
position object 1,BallXposition,60,BallZposition
position object 2,CubeXposition,40,80

`don't go pass outer edges
if BallXposition570 then BallStepX=(BallStepX)*(-1)
if BallZposition570 then BallStepZ=(BallStepZ)*(-1)

`check for collisions against player (cube)
if object collision(1,2)
position object 1,PrevBallXposition,60,PrevBallZposition
BallStepX=(BallStepX)*(-1)
BallStepZ=(BallStepZ)*(-1)
endif

`change player's position variable
if CubeXposition580 then CubeStepX=(CubeStepX)*(-1)

sync
loop