Collision Question
Blitz3D Forums/Blitz3D Beginners Area/Collision Question
| ||
How do you set (CollisionX,CollisionY,CollisionZ)'s Index? I keep getting an "Index out of range" Error. And there are no examples with these functions in the command reference. Also, As I move across a 3D terrain every time I get to a steep hill the camera shows the inside of the hill instead of the surface. I use the collision command slide2 mode. How would I get the camera to automatically go up when it gets to a steep hill and then decend again when I go down, I think checking CollisionY is the way to go. What is the best way to do it. Thanks in advance. |
| ||
well, give the camera an EntityType number then set up collisions between it and the landscape, so that the camera will collide and slide, and shouldn't go thru the landscape. Write back if you need any code :D |
| ||
I already have the collision checking between camera and landscape set up for slide2 mode. But sometimes when I go up a hill at a slight angle I see the inside of the hill instead of the surface. I need a means of checking the terrain height infront of me instead of right where I am. |
| ||
before you try checking the height in front of you, try changing the camera range. It's default setting is 1,1000. change the near value (1), to 0.1. see if that helps. |
| ||
maybe set a bigger entity radius. |
| ||
As I walk across my terrain I keep 15 above the terrain surface. But when I come to a hill I need a way to stay 15 away from the surface in front of me. I changed the camera min. range to 0.1 and it did help lessen the problem but I still get it on some hills. Am I the only one that has this problem? No other terrain walkers out there? |
| ||
have you tried sinu's idea of increasing the entityradius? You should also try parenting the camera to a pivot that is on the surface of the terrain and give it collision properties. Then when the pivot goes over a hill the camera will follow it up and down. Create the pivot, give it collision properties. Then create the camera, parent the camera to the pivot then set the camera to the desired height and move the pivot about. Do you have any code you could show. it will help me to understand what exactly is happening :D |
| ||
Here is my code so far: Graphics3D 1024,768,32,1 Global frame_count% Global fps% Global fps_timeout% Global frame_time% Global slowest_frame% Global frame_start% Global sped#=0.1 Global sp#=1 ;speed walking Global Angl#=30.0 ;max angle of up down look Global cr=10000 ;camera distance Global rd=127000 ;Rand max distance Global strt=0 ;Were to place camera at start Global af=30000 ;Auto fade distance Global ab=1700 Global x#=2 Global y#=15 Global z#=2 Global h#=15 ;Height above the ground Global MMY=-45 Global trees=5000 Dim treeb(Trees*4) Dim treec(Trees*4) Dim grass(500) c=1 ; Set collision type value ground=1 character=2 scenery=3 ClearTextureFilters SetBuffer BackBuffer() ClearWorld SeedRnd 32287 ;usual 32587 camera=CreateCamera() CameraRange(camera, 0.1, cr) CameraClsColor camera,40,40,190 RotateEntity camera , MMP,MMY,EntityRoll(camera) EntityType camera,character ;set camera for collision temp = MouseZSpeed() PositionEntity camera,x#,y#,z# light=CreateLight() RotateEntity light,90,0,0 Terrain=LoadTerrain( "media/D16.jpg" ) EntityType Terrain,ground ;set ground for collision Collisions character,ground,2,3 Collisions character,scenery,2,2 ;set collision response TerrainDetail terrain,600,True ScaleEntity terrain,500,3200,500 Ent02=LoadMesh("media/cantree.x") ;206 324 34 Ent01=LoadMesh("media/PineTree.x") Ent04=LoadMesh("media/deadtree.x") ;Bent Tree Trunk Ent03=LoadMesh("media/Trunk01.x") ;Streight Tree Trunk Tex90=LoadTexture( "media/1567.bmp",9) ;terrain tex Tex91=LoadTexture( "media/720.bmp",2) ;terrain tex Tex01=LoadTexture( "media/720.bmp",15) Tex02=LoadTexture( "media/721.bmp",15) Tex03=LoadTexture( "media/722.bmp",15) Tex04=LoadTexture( "media/713.bmp",15) Tex05=LoadTexture( "media/713.bmp",15) Tex07=LoadTexture( "media/1567.bmp",15) Tex08=LoadTexture( "media/cedar.jpg",9) sky=LoadTexture( "media/sky.bmp",9) TerrainShading terrain,True ; Texture terrain EntityTexture terrain,Tex90,0,1 ;************************************************************************* ;Test Stuff Starts Here ;************************************************************************* EntityTexture Ent03,Tex08 ;This is a Tree Trunk FitMesh Ent03,-1,-1,-1,2,2,2,True ScaleMesh Ent03,1,1,1 TurnEntity Ent03,0,0,0 te = 80 ScaleEntity Ent03,14,24,14 EntityAutoFade Ent03,ab,ab+300 ;These are not effected by dynamic EntityAutoFade EntityType Ent03,scenery ;set trunk for collision EntityTexture Ent04,Tex08 ;This is a Tree Trunk FitMesh Ent04,-1,-1,-1,2,2,2,True ScaleMesh Ent04,2,2,2.5 TurnEntity Ent04,0,0,10 te = 80 PositionEntity Ent04 ,-2,-2,-0 RotateEntity(Ent04,0,0,0) ScaleEntity Ent04,2,8,2 EntityAutoFade Ent04,ab,ab+300 EntityType Ent04,scenery ;set trunk for collision EntityTexture Ent01,Tex01 FitMesh Ent01,-1,-1,-1,2,2,2,True ScaleMesh Ent01,24,24,20 TurnEntity Ent01,0,0,0 te = 80 PositionEntity Ent01 ,te,TerrainY(Terrain,te,0,te)+42,te ScaleEntity Ent01,2,2,2 EntityTexture Ent02,Tex01 FitMesh Ent02,-1,-1,-1,2,2,2,True ScaleMesh Ent02,20,20,20 TurnEntity Ent02,0,0,0 te = 140 PositionEntity Ent02 ,te,TerrainY(Terrain,te,0,te)+28,te ScaleEntity Ent02,2,2,2 Gosub fade1 .skippit ; Tree2 = CopyEntity(Ent03,Ent01) ;another tree ;EntityType Ent01,scenery For tt = 1 To trees Treeb(tt) = CopyEntity(Ent01) ;another tree RotateEntity(Treeb(tt),0,Rnd(0,320),0) xx=Rnd(10,rd) zz=Rnd(10,rd) ScaleEntity Treeb(tt),4,4,4 ; EntityType Treeb(tt),scenery PositionEntity Treeb(tt),xx,TerrainY(Terrain,xx,0,zz)+80,zz Next Tree3 = CopyEntity(Ent04,Ent02) ;another tree For tt = 1 To trees Treec(tt) = CopyEntity(Ent02) ;another tree RotateEntity(Treec(tt),0,Rnd(0,320),0) xx=Rnd(10,rd) zz=Rnd(10,rd) ScaleEntity Treec(tt),4,4,4 PositionEntity Treec(tt),xx,TerrainY(Terrain,xx,0,zz)+70,zz Next Gosub fade1 Gosub fade2 ;************************************************************************* ;Main Loop Starts Here ;************************************************************************* ty=0 ;tree update count tey1#=5 h#=15 LP=0 ;lap count While Not KeyDown( 1 ) frame_start = MilliSecs() ;Keyboard control sped#=sp# + 0.1 tey1#=tey# If KeyDown( 31 ) Then sped#=0.1 ;S key If KeyDown( 16 ) Then sp#=sp#+0.1 ;Q key If KeyDown( 17 ) Then sp#=0.1 ;W key If KeyDown( 18 ) Then sp#=-0.09 ;E key If KeyDown( 42 ) Or KeyDown( 54 ) Then sped# = 1 ;L & R Shift If KeyDown( 29 ) Or KeyDown( 157 ) Then sped# = 5 ;L & R Ctrl If KeyDown( 44 )=True Then h#=h#-sped# ;Z key If KeyDown( 30 )=True Then h#=h#+sped# ;A key If KeyDown( 31 )=True Then h#=20 ;S key If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 ;Right If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 ;Left If KeyDown( 208 )=True Then MoveEntity camera,0,0,-sped# ;Down If KeyDown( 200 )=True Then MoveEntity camera,0,0,+sped# ;up If KeyDown( 45 ) Then PositionEntity camera,strt,90,strt ;X Key If KeyDown( 32 )=True Then cr=cr-10 Gosub cam01; If KeyDown( 33 )=True Then cr=cr+10 Gosub cam01; ;If KeyDown( 46 ) Then CameraRange(camera, 1, cr) If KeyDown( 46 ) Then cr=10000 Gosub cam01 If KeyDown( 47 ) Then cr=100000 Gosub cam01 If KeyDown( 48 ) Then ModifyTerrain Terrain,2,2,0.9,False If KeyDown( 49 ) Then ModifyTerrain Terrain,2,2,0.0,False ;Mouse Control MMP=EntityPitch(camera)+MouseYSpeed() MMY=EntityYaw(camera)-MouseXSpeed() ;turning If MMP >angl# ;Looking down MMP=angl# ElseIf MMP < -angl# ;Looking up MMP=-angl# EndIf RotateEntity camera , MMP,MMy,EntityRoll(camera) If Abs(mmy - ty)>1 Then Gosub fade3 ty=MMy If MouseDown(2) ;move forward y#=y#+sped# MoveEntity camera,0,0,sped# EndIf If MouseDown(1) ;move backard y#=y#-sped# MoveEntity camera,0,0,-sped# EndIf If MouseX() < 2 MoveMouse GraphicsWidth()-2, MouseY() tempX = MouseX() ElseIf MouseX() > GraphicsWidth()-2 MoveMouse 1, MouseY() tempX = MouseX() EndIf If MouseY() < 2 MoveMouse MouseX(), GraphicsHeight()-2 tempY = MouseY() ElseIf MouseY() > GraphicsHeight()-2 MoveMouse MouseX(), GraphicsHeight()-2 tempY = MouseY() EndIf .tst ;Camera rendering x#=EntityX(camera)If x#<0 Then x#=128000 ElseIf x#>128000 Then x#=0 y#=EntityY(camera) z#=EntityZ(camera)If z#<0 Then z#=128000 ElseIf z#>128000 Then z#=0 tey1#=TerrainY(terrain,x#,y#,z#)+h# ;auto camera ranging here If y1#<>y# Then LP=0 If LP =199 Then cr=120000 Gosub cam01 If LP >200 LP=200 Goto sk01 If TrisRendered()>56000 Then cr=cr-1000 Gosub cam01 .sk01 y1#=y# PositionEntity camera,x#,tey1#,z# UpdateWorld RenderWorld frame_time = MilliSecs() - frame_start show_info() Text 10,0, "direction: " + (EntityYaw(camera)+180) Text 10,48," X: "+x#+" Y: "+y#+" Z: "+z#+" CR: "+CR+" AF: "+af ; Text 0,72,"Height : "+H# Text 10,60,"Distance : "+ EntityDistance(Terrain,Camera)+" Height : "+h# Flip False lp=lp+1 Wend End .Fade1 EntityAutoFade Ent01,af,af+600 EntityAutoFade Ent02,af,af+600 EntityAutoFade Ent03,af,af+600 EntityAutoFade Ent04,af,af+600 RenderWorld 0 Return .Fade2 For tt = 1 To trees ShowEntity treeb(tt) ShowEntity treec(tt) If Not EntityInView(Treeb(tt),camera) Then HideEntity Treeb(tt) If Not EntityInView(Treec(tt),camera) Then HideEntity Treec(tt) EntityAutoFade Treeb(tt),af,af+300 EntityAutoFade Treec(tt),af,af+300 Next Return .Fade3 For tt = 1 To trees If Not EntityInView(Treeb(tt),camera) Then HideEntity Treeb(tt) Else ShowEntity treeb(tt) If Not EntityInView(Treec(tt),camera) Then HideEntity Treec(tt) Else ShowEntity treec(tt) Next Return .cam01 CameraRange (camera,0.1,cr) Return .cam02 CameraRange (camera,0.1,100000) Return Function show_info() frame_count = frame_count + 1 If MilliSecs() > fps_timeout Then fps_timeout = MilliSecs() + 1000 fps = frame_count frame_count = 0 EndIf If frame_time > slowest_frame Then slowest_frame = frame_time ; Text 10,0, "direction: " + (EntityYaw(camera)+180) Text 10,12," Triangles: " + TrisRendered() Text 10,24," Millisecs: " + frame_time Text 10,36," FPS: " + fps ; Text 10,48," X: "+x#+" Y: "+y#+" Z: "+z#+" CR: "+CR End Function ;End You will need your own trees, trunks, and textures for leaves though. |
| ||
Any chance you could e-mail me the source code and the media files. Send to rosscrooks@... |