hi guys, i was wondering if anyone could possibly help m here and point out what it is thats stopping my code from working. The problem is, when i run the code the ball keeps going forwards and won't bounce back.
Heres the code:
Graphics3D 800,600
SetBuffer BackBuffer()
Type BALL
Field x#
Field y#
Field z#
Field x_vector%
Field z_vector%
Field entity
Field collide
End Type
Type BRICK
Field x#
Field z#
Field status
End Type
;COLLISON VARIABLES
Const PLAYER_COL=1
Const WALL_COL=2
Const BALL_COL=3
;STATUS VARIABLES
Const SOLID=1
Const CLEAR=2
;SETUP CAMERA AND LIGHT
cam=CreateCamera()
light=CreateLight()
;LOAD THE SCENE
scene=LoadAnimMesh("level.3ds")
EntityType scene,WALL_COL,True
cam_piv=FindChild(scene,"cam") ;PIVOT FOR CAMERA
cam_x=EntityX(cam_piv)
cam_y=EntityY(cam_piv)
cam_z=EntityZ(cam_piv)
cam_focus=FindChild(scene,"focus") ;FOCUS POINT FOR CAMERA
bat=FindChild(scene,"bat") ;PLAYER
EntityType bat,PLAYER_COL
EntityRadius bat,15
ball.BALL=New BALL
ball\entity=FindChild(scene,"ball") ;AND FINALLY THE BALL (PHEW!!)
EntityType ball\entity,BALL_COL
EntityRadius ball\entity,10
ball\x=EntityX(ball\entity)
ball\y=EntityY(ball\entity)
ball\z=EntityZ(ball\entity)
ball\x_vector=1
ball\z_vector=1
PositionEntity cam,cam_x,cam_y,cam_z
EntityParent cam,cam_piv
PointEntity cam,cam_focus
EntityParent cam_piv,bat
;START THE COLLISIONS
Collisions PLAYER_COL,WALL_COL,2,2
Collisions BALL_COL,WALL_COL,2,2
time=CreateTimer(60)
;MAIN GAME LOOP
While Not KeyDown(1)
mouse_x=MouseXSpeed()/2
If ball\x_vector=1 Then ball\x=ball\x+2
If ball\x_vector=-1 Then ball\x=ball\x-2
If ball\z_vector=1 Then ball\z=ball\z+2
If ball\z_vector=-1 Then ball\z=ball\z-2
If KeyDown(200) Then MoveEntity cam_piv,0,0,1
If KeyDown(208) Then MoveEntity cam_piv,0,0,-1
If KeyDown(205) Then MoveEntity bat,1,0,0
If KeyDown(203) Then MoveEntity bat,-1,0,0
MoveEntity bat,mouse_x,0,0
PositionEntity ball\entity,ball\x,ball\y,ball\z
UpdateWorld
If EntityCollided(ball\entity,WALL_COL) Then ball\collide=1
If ball\collide=1 And ball\x_vector=1 Then ball\x_vector=-1:ball\collide=0
If ball\collide=1 And ball\x_vector=-1 Then ball\x_vector=1:ball\collide=0
If ball\collide=1 And ball\z_vector=1 Then ball\z_vector=-1:ball\collide=0
If ball\collide=1 And ball\z_vector=-1 Then ball\z_vector=1:ball\collide=0
RenderWorld
Text 0,0,ball\x+" "+ball\z
Flip
Wend
End
Thanks ever so much for any help
BLUE
Heres the code:
Graphics3D 800,600
SetBuffer BackBuffer()
Type BALL
Field x#
Field y#
Field z#
Field x_vector%
Field z_vector%
Field entity
Field collide
End Type
Type BRICK
Field x#
Field z#
Field status
End Type
;COLLISON VARIABLES
Const PLAYER_COL=1
Const WALL_COL=2
Const BALL_COL=3
;STATUS VARIABLES
Const SOLID=1
Const CLEAR=2
;SETUP CAMERA AND LIGHT
cam=CreateCamera()
light=CreateLight()
;LOAD THE SCENE
scene=LoadAnimMesh("level.3ds")
EntityType scene,WALL_COL,True
cam_piv=FindChild(scene,"cam") ;PIVOT FOR CAMERA
cam_x=EntityX(cam_piv)
cam_y=EntityY(cam_piv)
cam_z=EntityZ(cam_piv)
cam_focus=FindChild(scene,"focus") ;FOCUS POINT FOR CAMERA
bat=FindChild(scene,"bat") ;PLAYER
EntityType bat,PLAYER_COL
EntityRadius bat,15
ball.BALL=New BALL
ball\entity=FindChild(scene,"ball") ;AND FINALLY THE BALL (PHEW!!)
EntityType ball\entity,BALL_COL
EntityRadius ball\entity,10
ball\x=EntityX(ball\entity)
ball\y=EntityY(ball\entity)
ball\z=EntityZ(ball\entity)
ball\x_vector=1
ball\z_vector=1
PositionEntity cam,cam_x,cam_y,cam_z
EntityParent cam,cam_piv
PointEntity cam,cam_focus
EntityParent cam_piv,bat
;START THE COLLISIONS
Collisions PLAYER_COL,WALL_COL,2,2
Collisions BALL_COL,WALL_COL,2,2
time=CreateTimer(60)
;MAIN GAME LOOP
While Not KeyDown(1)
mouse_x=MouseXSpeed()/2
If ball\x_vector=1 Then ball\x=ball\x+2
If ball\x_vector=-1 Then ball\x=ball\x-2
If ball\z_vector=1 Then ball\z=ball\z+2
If ball\z_vector=-1 Then ball\z=ball\z-2
If KeyDown(200) Then MoveEntity cam_piv,0,0,1
If KeyDown(208) Then MoveEntity cam_piv,0,0,-1
If KeyDown(205) Then MoveEntity bat,1,0,0
If KeyDown(203) Then MoveEntity bat,-1,0,0
MoveEntity bat,mouse_x,0,0
PositionEntity ball\entity,ball\x,ball\y,ball\z
UpdateWorld
If EntityCollided(ball\entity,WALL_COL) Then ball\collide=1
If ball\collide=1 And ball\x_vector=1 Then ball\x_vector=-1:ball\collide=0
If ball\collide=1 And ball\x_vector=-1 Then ball\x_vector=1:ball\collide=0
If ball\collide=1 And ball\z_vector=1 Then ball\z_vector=-1:ball\collide=0
If ball\collide=1 And ball\z_vector=-1 Then ball\z_vector=1:ball\collide=0
RenderWorld
Text 0,0,ball\x+" "+ball\z
Flip
Wend
End
Thanks ever so much for any help
BLUE