Movement and the Camera
Blitz3D Forums/Blitz3D Beginners Area/Movement and the Camera
| ||
I'm having some trouble with my camera/movement system. The camera looks around with the mouse, which is good, except one thing is that it goes off screen sometimes and I forgot how to make it go back if it leaves the screen. The main issue, though, is that I want the movement to be related to the camera. By this I mean I don't want the player to be able to fly, so I turned "moveentity" into "translateentity". The problem now is that you always move the same way regardless of which direction you are looking at. I don't know if that makes sense. Here is the code so you can see for yourself; mx# = mx# + MouseXSpeed() my# = my# + MouseYSpeed() If mx# > 360 Then mxs# = 0 If mx# < 0 Then mx# = 360 If my# > 80 Then my# = 80 If my# < -80 Then my# = -80 RotateEntity cam,my#,-mx#,0 If KeyDown(17) Then TranslateEntity cam,0,0,0.05 EndIf If KeyDown(31) Then TranslateEntity cam,0,0,-0.05 EndIf If KeyDown(30) Then TranslateEntity cam,-0.05,0,0 EndIf If KeyDown(32) Then TranslateEntity cam,0.05,0,0 EndIf Thank you for your help! |
| ||
your description of want you want is very "minimalistic", so I dont know whether my aswer is a help for you... Could it be, that you want to have a camera like in ego-shooters? A player that moves around and a camera which is mounted on his head? So you should first create the player entity and then create the camera as a child of the player entity. During the game you should use the player entity for all left/right turns and all movements. For the up/down turns you should only use the camera entity. MoveEntity() is in this relation better than TranslateEntity(). The movements are always relativ to the previous position and therefore more realistic. By the way... it has nothing to do with "flying". You can prevent flying by create a plane and care about collisions of the player with the ground. |