You're quite right b32! However, I have corrected the code and made a modification to the cube definitions (I was extending the Y axis and then rotating them so they lay on the floor - don't ask me why!) and whilst CameraPick now works ok, Collisions do not - unless I do not scale the cubes, in which case they work perfectly.
My code is as follows:
I must be doing something wrong somewhere - because no matter what I try, a "train" will pass almost 1/3 of the way through another before Blitz3D registers a collision. Can anyone tell me why my code does not work? (Apologies for the camera - another eve or two spent in the archives til I learn how to improve this methinks...) :o)
My code is as follows:
Graphics3D 1024,768,32,2 SetBuffer BackBuffer() Color 255,255,255 SeedRnd MilliSecs() Local trainsel=-1 Local last_chkpt=MilliSecs() Local framecount Local fps Local newtrain=0 Local newtype=0 ;Local mouseimage=LoadImage("mouse.bmp") Local type_camera=1 Local type_ground=2 Local type_train=3 Dim train(2) ;MaskImage mouseimage,192,192,255 Collisions type_camera,type_ground,2,1 Collisions type_train,type_train,3,1 ; setup entities light=CreateLight() camera=CreateCamera() PositionEntity camera, 0,6,-16 RotateEntity camera,15.0,0,0 EntityType camera,type_camera ground=CreatePlane() EntityColor ground, 34,53,123 EntityType ground,type_ground For k=0 To 2 train(k)=CreateCube() ScaleEntity train(k),1,1,4 EntityBox train(k), -1,-1,-4,2,2,8 PositionEntity train(k),k*5,1,Rand(30) EntityPickMode train(k),3 EntityType train(k),type_train Next While Not KeyDown( 1 ) ; check for selection If MouseHit(1) Then For k=0 To 2 EntityColor train(k),255,255,255 Next trainsel=-1 newtype=0 newtrain=CameraPick(camera,MouseX(),MouseY()) If newtrain<>0 Then newtype=GetEntityType(newtrain) If newtype=type_train Then For k=0 To 2 If train(k)=newtrain Then trainsel=k Exit EndIf Next EntityColor PickedEntity(),255,255,0 EndIf EndIf EndIf ; check for move/rotate If KeyDown(42) Then ; LEFTSHIFT If KeyDown(200) Then MoveEntity camera,0,0,0.1 ElseIf KeyDown(208) Then MoveEntity camera,0,0,-0.1 EndIf ElseIf KeyDown(29) Then ; LEFT CTRL If KeyDown(200) Then MoveEntity camera,0,0.1,0 ElseIf KeyDown(208) Then MoveEntity camera,0,-0.1,0 EndIf ElseIf trainsel>-1 Then If KeyDown(200) Then If KeyDown(203) Then TurnEntity train(trainsel),0,1.0,0 EndIf If KeyDown(205) Then TurnEntity train(trainsel),0,-1.0,0 EndIf MoveEntity train(trainsel),0,0,-0.1 EndIf EndIf ; update screen UpdateWorld RenderWorld framecount=framecount+1 If MilliSecs()-last_chkpt>=1000 last_chkpt=MilliSecs() fps=framecount framecount=0 EndIf Text 0,0,"FPS: "+fps ; DrawImage mouseimage,MouseX(),MouseY() Flip Wend For k=0 To 2 FreeEntity train(k) Next FreeImage mouseimage End
I must be doing something wrong somewhere - because no matter what I try, a "train" will pass almost 1/3 of the way through another before Blitz3D registers a collision. Can anyone tell me why my code does not work? (Apologies for the camera - another eve or two spent in the archives til I learn how to improve this methinks...) :o)