Hey, i have this tank game i'm messing with as my first real 3d project. First of all i'm new to blitz3d, i'v been using the demo for about 5 days before Christmas, then got the real thing on Christmas, so just over a week of experiance.
Anyways my tank can be controled by the player to go around the terrain. i'm using the following code to keep him above the terrain:
now then it looks very strange, what i'm looking for is a code that allows the tank or any car, to rotate to the terrain around him in realtime.
heres my complete code:
Anyone? also i tried using that one guys code in the CA, somthing about making it happen without using child or pivots, i tried incorperating it into my code, didnt work, if any of you know how to incorporate it into my code that'd be great otherwise do you know any other methods mabey ones that use "Pivots and child entitys"
Thanks,
Yahfree
Anyways my tank can be controled by the player to go around the terrain. i'm using the following code to keep him above the terrain:
ex#=EntityX(player):ez#=EntityZ(player) PositionEntity player,ex,TerrainY( land,ex,0,ez )+1.5,ez
now then it looks very strange, what i'm looking for is a code that allows the tank or any car, to rotate to the terrain around him in realtime.
heres my complete code:
;Sets the graphics mode and the backbuffer Graphics3D 1680,1050,16,1 SetBuffer BackBuffer() ;Global stuff Global RIGHT_ARR=205, LEFT_ARR=203, UP_ARR=200, DOWN_ARR=208, SPAC_BAR=57, R_CTR=157, N_0=82 Global cam1, player, land, skybox, playerhead Global velocity#=0 Global x#=0, y#=0, z#=-10 ;Makes the camera cam1=CreateCamera() CameraViewport cam1,0,0,1680,1050 PositionEntity cam1,0,7+40,-35 ;RotateEntity cam1,0,180,0 ;Makes a light light1=CreateLight ;Calls some functions that dont loop in realtime maketerrain() Loadplayer("Models&Textures\warrior\warriorbody.3ds") makeskybox() ;Bullet type Type bullet Field sprite, timeout End Type ;!@#@$@#!$@!#$#@%#$%$%^%^&^%*&^(*&()*)*()%^$^%#@ ;!@#$!@#$@#%@#$ MAIN GAME LOOP !#$@#$@%#@$^$%@#$ ;#@$!@#$@!#$@#%#$%@#$%@$##@!%#$@%#$%@#$%#@$@%@%$ While Not KeyHit(1) ;Calls some loop functions playermove() chasecam() ;Makes it so the skybody is always in the same spot as the player PositionEntity skybox,EntityX(player),EntityY(player),EntityZ(player) ;this little code translates the raw velocity code into a fake MPH, that will be displayed in the center of the screen MPH%=velocity#*30 MPH%=MPH%-MPH-MPH ;Updates and renders the world UpdateWorld RenderWorld ;2D stuff ;Text, with some maths to show xyz, and the velocity Color 255,0,0 Text GraphicsWidth()/2,GraphicsHeight()/2,"MPH"+MPH Text 50,70,"X: "+EntityX(player)+" Y: "+EntityY(player)+" Z: "+EntityZ(player) Color 255,255,255 ;flip the backbuffer stuff onto the front buffer, and end when the ESC key is pressed Flip Wend ;!@#@$@#!$@!#$#@%#$%$%^%^&^%*&^(*&()*)*()%^ ;!@#$!@#$@#%@#$ FUNCTIONS !#$@#$@%#@$^$%@#$ ;#@$!@#$@!#$@#%#$%@#$%@$##@!%#$@%#$%@#$%#@$ ;Loads the player tank both parts, and resizes 'em Function Loadplayer(file$) ;Tanks body player=LoadMesh(file$) ptex=LoadTexture("Models&Textures\warrior\warrior.jpg") EntityTexture player,ptex ScaleEntity player,5,5,5 RotateEntity player,0,180,0 EntityType player,t_player PositionEntity player,x,y,z ;Tanks head playerhead=LoadMesh("Models&Textures\warrior\warriorhead.3ds") EntityTexture playerhead,ptex PositionEntity playerhead,0,41.99,-13 ScaleEntity playerhead,5,5,5 RotateEntity playerhead,0,180,0 End Function ;All the movement and control factors go here Function playermove() ;Accelerate and if the key isnt down then decelerate If KeyDown(UP_ARR) And velocity#>-1.001 Then velocity#=velocity#-0.001 Else If velocity#<0.0 Then velocity#=velocity#+0.001 ;If the speed is 0 then reverse, and if reverse isnt happening decelerate If KeyDown(DOWN_ARR) And velocity#>-0.00001 And velocity#<1.0 Then velocity#=velocity#+0.001 Else If velocity#>0.0 Then velocity#=velocity#-0.001 ;Turn left If KeyDown(LEFT_ARR) Then TurnEntity player,0,0.5,0 End If ;Turn right If KeyDown(RIGHT_ARR) Then TurnEntity player,0,-0.5,0 End If ;Turns the tanks head left If KeyDown(R_CTR) Then TurnEntity playerhead,0,2,0 End If ;Turns the tanks head right If KeyDown(N_0) Then TurnEntity playerhead,0,-2,0 End If ;Instantly stops the tank, NOTE: fix this If KeyHit(SPAC_BAR) Then velocity#=0 ;Puts the velocity code in motion MoveEntity player,0,0,velocity# ;Make sure the tank stays ontop of the terrain ex#=EntityX(player):ez#=EntityZ(player) PositionEntity player,ex,TerrainY( land,ex,0,ez )+1.5,ez ;"Glues the tanks top onto the tanks body but not viseversa, so the tank head can move without moving the body EntityParent playerhead,player End Function ;Makes the terrain Function maketerrain() land_tex=LoadTexture( "Terrian stuff\terrain_tex.jpg" ) ScaleTexture land_tex,10,10 land=LoadTerrain( "Terrian stuff\terrain_hmap.jpg" ) ScaleEntity land,8,100,8 PositionEntity land,-2048,0,-2048 EntityTexture land,land_tex TerrainDetail land,1000,True EntityType land,t_land End Function ;makes the camera Function chasecam() EntityParent cam1,player End Function ;Creates the skybox Function makeskybox() skybox=CreateMesh() ;front face b=LoadBrush( "Terrian stuff\front.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0 AddVertex s,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;left face b=LoadBrush( "Terrian stuff\left.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,+1,+1,-1,0,0:AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1:AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;back face b=LoadBrush( "Terrian stuff\back.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,+1,+1,+1,0,0:AddVertex s,-1,+1,+1,1,0 AddVertex s,-1,-1,+1,1,1:AddVertex s,+1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;right face b=LoadBrush( "Terrian stuff\right.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,-1,+1,+1,0,0:AddVertex s,-1,+1,-1,1,0 AddVertex s,-1,-1,-1,1,1:AddVertex s,-1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;top face b=LoadBrush( "Terrian stuff\up.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,-1,+1,+1,0,1:AddVertex s,+1,+1,+1,0,0 AddVertex s,+1,+1,-1,1,0:AddVertex s,-1,+1,-1,1,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;bottom face b=LoadBrush( "Terrian stuff\down.jpg",49 ) s=CreateSurface( skybox,b ) AddVertex s,-1,-1,-1,1,0:AddVertex s,+1,-1,-1,1,1 AddVertex s,+1,-1,+1,0,1:AddVertex s,-1,-1,+1,0,0 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ScaleMesh skybox,100,100,100 FlipMesh skybox EntityFX skybox,1 EntityOrder skybox,10 End Function
Anyone? also i tried using that one guys code in the CA, somthing about making it happen without using child or pivots, i tried incorperating it into my code, didnt work, if any of you know how to incorporate it into my code that'd be great otherwise do you know any other methods mabey ones that use "Pivots and child entitys"
Thanks,
Yahfree