Turning in a 3d game
Blitz3D Forums/Blitz3D Beginners Area/Turning in a 3d game
| ||
Hello, I was working on a new project in blitz3d (Ive never tried 3d before), and when I tried to make it so you could turn and move, it wouldnt work.Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,0 light=CreateLight() RotateEntity light,90,0,0 ; Create terrain terrain=CreateTerrain(16) guncamera = CreateCamera() CameraClsMode guncamera,0,1 PositionEntity guncamera,0,65535+6,0 gun=CreateCylinder() ScaleEntity gun,1,3,1 RotateEntity gun,90,0,0 TranslateEntity gun,0,65535+4,4 EntityColor gun,001,002,015 ;grass_tex=LoadTexture( "texg.bmp" ) ;EntityTexture terrain,grass_tex While Not KeyDown( 1 ) mxspd#=MouseXSpeed() myspd#=MouseYSpeed() MoveMouse 320,240 If mxspd# = 1 TurnEntity camera,0,-1,0 If mxspd# = -1 TurnEntity camera,0,1,0 If mxspd# = 2 TurnEntity camera,0,-2,0 If mxspd# = -2 TurnEntity camera,0,2,0 If mxspd# = 3 TurnEntity camera,0,-3,0 If mxspd# = -3 TurnEntity camera,0,3,0 If mxspd# > 3 TurnEntity camera,0,-3,0 If mxspd# < -3 TurnEntity camera,0,3,0 If myspd# = 1 pitch#=pitch#+1 If myspd# = -1 pitch#=pitch#-1 If myspd# = 2 pitch#=pitch#+2 If myspd# = -2 pitch#=pitch#-2 If myspd# = 3 pitch#=pitch#+3 If myspd# = -3 pitch#=pitch#-3 If myspd# > 3 pitch#=pitch#+3 If myspd# < -3 pitch#=pitch#-3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RotateEntity camera,pitch#,yaw#,roll#;Here <------------------------------------------ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If KeyDown( 30 ) Then MoveEntity camera,-0.05,0,0 If KeyDown( 32 )=True Then MoveEntity camera,0.05,0,0 If KeyDown( 31 )=True Then MoveEntity camera,0,0,-0.05 If KeyDown( 17 )=True Then MoveEntity camera,0,0,0.05 RenderWorld Flip Wend When the RotateEntity camera,pitch#,yaw#,roll# command is commented, you can so left and right, and when it isnt, you can go up and down, but they dont work at the same time. WASD works though. Does anyone know how to fix this problem? |
| ||
You are not setting the yaw value anywhere... |
| ||
I dont want to move the yaw, just pitch |
| ||
Try this. I added some code but got rid of much more.Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,0 light=CreateLight() RotateEntity light,90,0,0 ; Create terrain terrain=CreateTerrain(16) guncamera = CreateCamera() CameraClsMode guncamera,0,1 PositionEntity guncamera,0,65535+6,0 gun=CreateCylinder() ScaleEntity gun,1,3,1 RotateEntity gun,90,0,0 TranslateEntity gun,0,65535+4,4 EntityColor gun,001,002,015 ;grass_tex=LoadTexture( "texg.bmp" ) ;EntityTexture terrain,grass_tex While Not KeyDown( 1 ) mxspd#=MouseXSpeed() myspd#=MouseYSpeed() MoveMouse 320,240 ;GET RID OF THIS CODE BELOW ;If mxspd# = 1 TurnEntity camera,0,-1,0 ;If mxspd# = -1 TurnEntity camera,0,1,0 ;If mxspd# = 2 TurnEntity camera,0,-2,0 ;If mxspd# = -2 TurnEntity camera,0,2,0 ;If mxspd# = 3 TurnEntity camera,0,-3,0 ;If mxspd# = -3 TurnEntity camera,0,3,0 ;If mxspd# > 3 TurnEntity camera,0,-3,0 ;If mxspd# < -3 TurnEntity camera,0,3,0 ;If myspd# = 1 TurnEntity camera, 1,0,0 ;If myspd# = -1 TurnEntity camera, -1,0,0 ;If myspd# = 2 TurnEntity camera, 2,0,0 ;If myspd# = -2 TurnEntity camera, ;If myspd# = 3 pitch#=pitch#+3 ;If myspd# = -3 pitch#=pitch#-3 ;If myspd# > 3 pitch#=pitch#+3 ;If myspd# < -3 pitch#=pitch#-3 ;SIMPLY USE THIS LINE BELOW TurnEntity camera, myspd#/10, -mxspd#/10,0 ;THESE LINES KEEP THE CAMERA FROM TILTING TO THE LEFT OR RIGHT Local out_of_kilter# = EntityRoll(camera) If out_of_kilter# <> 0 TurnEntity camera, 0,0,-out_of_kilter# End If ;YOU DONT NEED THIS LINE EITHER WAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;RotateEntity camera,pitch#,yaw#,roll#;Here <------------------------------------------ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If KeyDown( 30 ) Then MoveEntity camera,-0.05,0,0 If KeyDown( 32 )=True Then MoveEntity camera,0.05,0,0 If KeyDown( 31 )=True Then MoveEntity camera,0,0,-0.05 If KeyDown( 17 )=True Then MoveEntity camera,0,0,0.05 RenderWorld Flip Wend |
| ||
@Nike - I don't think you realise - you do want to alter the yaw - that is what your turn entity lines were doing but when you also used the rotate entity command the yaw value was always set to zero so the turnentity commands for left/right were effectively not doing anything. |
| ||
Oh, well thank you for explaining that Matty, and thank you for the code Drak. |
| ||
Here's a further thing that might be useful: In a walktrough you should create a basic player pivot, then parent the camera to it. You will them move this player pivot, as well as turn its Yaw, to walk around in a FPS way. But to look up and down you will alter the pitch of the camera only . This way you can move forward normally, even if you look straight down to your feet or up to the sky. |