Driving Game (WIP)
Blitz3D Forums/Blitz3D Programming/Driving Game (WIP)
| ||
A few years ago, I downloaded and generated DEM and TIGER data into a bitmap file and used the bitmap file to generate a "train layout" for Auran Trainz 2004 program. Now, I loaded the bitmap file into a Blitz BASIC program, created a brush, and applied the bitmap file on a cube that is 3028 units wide and 4108 units long. The bitmap file is 3028 pixels wide and 4108 pixels long. How do I create a camera view that looks like I'm driving a car and move the camera around using the arrow keys? |
| ||
Something quick to get you started:Graphics3D 800,600 cam = CreateCamera() MoveEntity cam, 0, 1, 0 grid_tex=CreateTexture( 32,32,8 ) ScaleTexture grid_tex,10,10 SetBuffer TextureBuffer( grid_tex ) Color 0,0,64:Rect 0,0,32,32 Color 0,0,255:Rect 0,0,32,32,False SetBuffer BackBuffer() grid_plane=CreatePlane() EntityTexture grid_plane,grid_tex While Not KeyHit(1) If KeyDown(57) Then MoveEntity cam, 0, 0, .3 ;spacebar If KeyDown(203) Then TurnEntity cam, 0, .4, 0 ;left key If KeyDown(205) Then TurnEntity cam, 0, -.4, 0 ;right key RenderWorld() Flip Wend |
| ||
Uhh, okay, what about a reverse key? Well, for a driving game, if you're stuck in trouble, there should be a way to back out of trouble. It's done in NASCAR and Indy, and should be simulated here. Nice wireframe grid, btw... |
| ||
WolRon, You are such a nice person! IPete2. |
| ||
Iron Bob, Read the manual! The code is very easy to change, you will be add that "simulation" really easy if you understand the code. |
| ||
"Read the manual!" How quaint! As someone else has said, "When all else fails, read the manual." Gosh, if we all read the manual, how would we get any programming done? LOL |
| ||
I learned by reading the manual :o) And looking at the examples :o) |
| ||
In my program, the camera view looks like a bird's eye view of the ground. How do I change it into a view that looks like I'm driving a car? I wish that there is a printed manual for Blitz BASIC 3D. Is it possible to use a bitmap that has two different colors to simulate ground and rivers using some kind of 3D mesh? |
| ||
Hey Jeff! To reposition the camera just use the "Positionentity" command, make the Y coordinate lower! (You should look into Height Maps. I've never really used 'em, but my friend designed some pretty cool stuff with those. It maight be a solution for that river thingee) |
| ||
I think that I got my program working but how do I create the sky?Graphics3D 640,480,16,0 SetBuffer BackBuffer() camera=CreateCamera() ;PositionEntity camera,0,1,0 RotateEntity camera,-90,0,0 light=CreateLight() cube=CreateCube() ScaleMesh cube,3028,4108,1 PositionEntity cube,0,0,5 tex=LoadTexture("nycta.bmp") brush=CreateBrush() BrushTexture brush,tex PaintMesh cube,brush MoveEntity camera,0,0,0 While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05 RenderWorld Flip Wend End |
| ||
more quick and dirty code.... . . PaintMesh cube,brush MoveEntity camera,0,0,0 ClsColor 70, 80, 255 CameraClsMode camera, 0, 1 While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.5 If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.5 Cls RenderWorld Flip Wend End |
| ||
I tried to run some of the example programs in the Command Reference section of the manual but they can't find bitmap files that are needed such as CreateTerrain command. I have Blitz BASIC 3D 1.91. |
| ||
I found out where the media files are when I read another thread in this forum: http://www.blitzbasic.com/Community/posts.php?topic=51101 |
| ||
There is a printed copy of the manual for B3d, I'd to fight tooth and nail for mine... but they do exist. |
| ||
Why does my program slow down after I add about 500 3D boxes to my program to represent buildings?Graphics3D 800,600 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,70,80,255 RotateEntity camera,-90,0,0 light=CreateLight() plane=CreatePlane() EntityColor plane,63,63,63 For x = 0 To 12 For z = 0 To 44 cube = CreateCube() ScaleMesh cube,75,25,25 EntityColor cube,191,0,0 PositionEntity cube,x * 100,0,z * 50 Next Next While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-1 If KeyDown( 200 )=True Then MoveEntity camera,0,0,1 RenderWorld Flip Wend End |
| ||
Graphics3D 800,600 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,70,80,255 RotateEntity camera,-90,0,0 light=CreateLight() plane=CreatePlane() EntityColor plane,63,63,63 Building = createcube() scalemesh Building , 75, 25, 25 positionmesh Building, 0, 25, 0 hideentity Building For x = 0 To 12 For z = 0 To 44 cube = copyentity( Building ) EntityColor cube,191,0,0 PositionEntity cube,x * 100,0,z * 50 Next Next While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-1 If KeyDown( 200 )=True Then MoveEntity camera,0,0,1 RenderWorld Flip Wend End Try using instances of a mesh it's much faster... or at least should be. Notice the use of Copyentity(). Stevie |
| ||
Why does my program slow down after I add about 500 3D boxes to my program to represent buildings? Lots of individual entities will slow B3D down, especially if you have debug mode turned on. Ideally you'd make your level / world / racetrack as a single mesh in a modelling program such as 3DSMax, AC3D, Blender etc... I wish that there is a printed manual for Blitz BASIC 3D I have my printed Blitz3D manual (the sprial bound one from when the product was first released) upstairs in the cupboard . I never use it so make me an offer if you want! |
| ||
Here's the code so far:Graphics3D 800,600 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,70,80,255 light=CreateLight() RotateEntity light,0,90,0 plane=CreatePlane() EntityColor plane,63,63,63 tex=LoadTexture("buildingwall03.tga") building=CreateCube() ScaleMesh building,75,25,25 EntityTexture building,tex PositionMesh building,0,25,0 HideEntity building For x = 0 To 50 For y = 0 To 25 cube=CopyEntity(building) PositionEntity cube,y * 200,0,x * 100 Next Next MoveEntity camera,100,5,0 While Not KeyDown( 1 ) If KeyDown( 205 )=True Then TurnEntity camera,0,-0.5,0 If KeyDown( 203 )=True Then TurnEntity camera,0,0.5,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-1 If KeyDown( 200 )=True Then MoveEntity camera,0,0,1 RenderWorld Flip Wend End Two questions: How to tile a bitmap texture three times along the long walls and one time along the short walls of the buildings? How to set up collision tests between camera and buildings? |
| ||
Because the 'buildings' are primitives (i.e. created with CreateCube) they only have one surface, each face is made of two triangles so the texture will be stretched along them. My advice would be to make the buildings 3 cubes high As for the collisions, you need to set the EntityType, which tells the program which objects collide with which and the responses to those collisions. |
| ||
I finally got the program working properly. What about car physics? Here's the code so far:Graphics3D 800,600 SetBuffer BackBuffer() camera=CreateCamera() CameraClsColor camera,70,80,255 light=CreateLight() RotateEntity light,0,90,0 plane=CreatePlane() EntityColor plane,63,63,63 tex1=LoadTexture("buildingwall03.tga") tex2=LoadTexture("concrete2.tga") building=CreateCube() ScaleMesh building,25,25,25 EntityTexture building,tex1 PositionMesh building,0,25,0 HideEntity building sidewalk=CreateCube() ScaleMesh sidewalk,35,1,35 EntityTexture sidewalk,tex2 PositionMesh sidewalk,0,1,0 HideEntity sidewalk For x = 0 To 50 For y = 0 To 50 cube01=CopyEntity(building) cube02=CopyEntity(sidewalk) EntityType cube02,2 PositionEntity cube01,y * 100,1,x * 100 PositionEntity cube02,y * 100,-1,x * 100 Next Next MoveEntity camera,50,5,0 EntityType camera,1 EntityRadius camera,5 While Not KeyDown( 1 ) If JoyX() < -0.1 Then TurnEntity camera,0,0.5,0 If JoyX() > 0.1 Then TurnEntity camera,0,-0.5,0 If JoyY() < -0.1 Then MoveEntity camera,0,0,1 If JoyY() > 0.1 Then MoveEntity camera,0,0,-1 If KeyDown( 205 )=True Then TurnEntity camera,0,-0.5,0 If KeyDown( 203 )=True Then TurnEntity camera,0,0.5,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-1 If KeyDown( 200 )=True Then MoveEntity camera,0,0,1 Collisions 1,2,2,1 UpdateWorld RenderWorld Flip Wend End |
| ||
Nice so far, Jeff! Sorry, I rushed my code above and Im glad you sorted the collisions! As for Car Physics - Be prepared, because as complex and 'realistic' as you want to make it, (somewhat obviously), the mroe complex the programming will be. There ARE sets of functions available to be incorporated into Blitz (Have a look around these forums for Tokamak), but of course, these take a deal of setting up. If you can specify the sort of level of physics you are after, Il see if I can help :) |
| ||
I used the example program called "Drive" that came with the latest version of Blitz BASIC 3D (I think version 1.91) for car physics. I tried to use my driving controller to move the car but it won't run in reverse. Here's the code so far:Global info1$="Driver" Include "../start.bb" Const GRAVITY#=-.01 Const BODY=1,WHEEL=2,SCENE=3 Collisions BODY,SCENE,2,3 Collisions WHEEL,SCENE,2,3 terr=CreatePlane() tex=LoadTexture( "terrain-1.jpg" ) ScaleTexture tex,50,50 EntityTexture terr,tex EntityType terr,SCENE car=LoadMesh( "car.x" ) ScaleMesh car,1,1,-1 FlipMesh car FitMesh car,-1.5,-1,-3,3,2,6 PositionEntity car,0,70,0 EntityShininess car,1 EntityType car,BODY Global wheels[4] cnt=1 For z#=1.5 To -1.5 Step -3 For x#=-1 To 1 Step 2 wheels[cnt]=CreateSphere( 8,car ) EntityAlpha wheels[cnt],.5 ScaleEntity wheels[cnt],.5,.5,.5 EntityRadius wheels[cnt],.5 PositionEntity wheels[cnt],x,0,z EntityType wheels[cnt],WHEEL cnt=cnt+1 Next Next light=CreateLight() TurnEntity light,45,45,0 target=CreatePivot( car ) PositionEntity target,0,5,-12 camera=CreateCamera() CameraClsColor camera,0,128,255 speed#=0 x_vel#=0:prev_x#=EntityX( car ) y_vel#=0:prev_y#=EntityY( car ) z_vel#=0:prev_z#=EntityZ( car ) While Not KeyHit(1) zx#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2 zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2 zy#=(EntityY( wheels[2],True )+EntityY( wheels[4],True ))/2 zy=zy-(EntityY( wheels[1],True )+EntityY( wheels[3],True ))/2 zz#=(EntityZ( wheels[2],True )+EntityZ( wheels[4],True ))/2 zz=zz-(EntityZ( wheels[1],True )+EntityZ( wheels[3],True ))/2 AlignToVector car,zx,zy,zz,1 zx#=(EntityX( wheels[1],True )+EntityX( wheels[2],True ))/2 zx=zx-(EntityX( wheels[3],True )+EntityX( wheels[4],True ))/2 zy#=(EntityY( wheels[1],True )+EntityY( wheels[2],True ))/2 zy=zy-(EntityY( wheels[3],True )+EntityY( wheels[4],True ))/2 zz#=(EntityZ( wheels[1],True )+EntityZ( wheels[2],True ))/2 zz=zz-(EntityZ( wheels[3],True )+EntityZ( wheels[4],True ))/2 AlignToVector car,zx,zy,zz,3 cx#=EntityX( car ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( car ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( car ):z_vel=cz-prev_z:prev_z=cz cnt=1 For z=1.5 To -1.5 Step -3 For x=-1 To 1 Step 2 PositionEntity wheels[cnt],x,-1,z cnt=cnt+1 Next Next If (speed < -0.01 Or speed > 0.01) And (JoyX() < -0.1 Or KeyDown( 203 )=True) TurnEntity car,0,3,0 If (speed < -0.01 Or speed > 0.01) And (JoyX() > 0.1 Or KeyDown( 205 )=True) TurnEntity car,0,-3,0 If EntityCollided( car,SCENE ) If JoyY() < -0.01 Or KeyDown( 200 )=True speed=speed+.02 If speed>.7 speed=.7 Else If JoyY > 0.01 Or KeyDown( 200 )=True speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity car,0,0,speed TranslateEntity car,0,GRAVITY,0 Else TranslateEntity car,x_vel,y_vel+GRAVITY,z_vel EndIf If speed>=0 dx#=EntityX( target,True )-EntityX( camera ) dy#=EntityY( target,True )-EntityY( camera ) dz#=EntityZ( target,True )-EntityZ( camera ) TranslateEntity camera,dx*.1,dy*.1,dz*.1 EndIf PointEntity camera,car UpdateWorld RenderWorld Flip Wend End |
| ||
ah - not looked at any examples for ages. It's late here right now, so looking at this is tomorows job ;) |
| ||
If JoyY needs to be If JoyY() Without the (), JoyY is just an empty variable, not a joystick function :) |
| ||
I need a new pair of eyes. How can I miss the missing () after JoyY? |
| ||
I do it all the time with PickedEntity() |
| ||
As do I with PickedNose() The bogey always falls on the floor. |
| ||
Heh - my 'favourite' is always typing SeedRnd(Millisecs) or - Next F (damn speccy legacy lives on hehe!) :( |