Walking using mouse
Blitz3D Forums/Blitz3D Beginners Area/Walking using mouse
| ||
Can anyone post a code to user archive of a simple 3rd person moving using mouse (no click). Just move the mouse to front/back to walk front and back and mouse left/right to change angle (Like and old version of Doom). Thanks in advance. I kind of stuck here.. |
| ||
Wait, if you want it to look like "Doom" then you want 1st person camera code. So which is it, 3rd person or 1st person? Either way there are plenty of code samples to work from. Look in the Samples which come with Blitz and/or in the Code archives. Just make small adjustments like MoveEntity instead of RotateEntity based on MouseYSpeed. |
| ||
Ya thanks for fast reply. I try quite a lot but I can't find the one that using mouse to move. All I got either using keyboard or mouse button. What I always found is like: If KeyDown(?) then Moveforward() or If MouseDown(?) then ... I have no idea of how to triger when mouse move forward. ;( I got some idea to create a timer and check last mouse position and compare with current mouse position but when mouse reach at the top of the screen, I cannot make it go down and ... I don't know how to explain. ;> Ok.. the other way, remenber the old Doom, we walk around just using mouse movement only. (button is only for fire) This is the kind that I look for.. ;~~( About the 1st and 3rd person, sorry..I think its 1st person. but don't bother that.... If any one have time on that, thanks a lot |
| ||
As I alluded to, to track how much the mouse moved use MouseXSpeed and MouseYSpeed. Then use RotateEntity and MoveEntity appropriately to move the camera around. It's that simple. So you'ld have code something like this: [setup your 3D scene and create a camera called "camera"] While Not KeyHit(1) RotateEntity camera,0,MouseXSpeed(),0 MoveEntity camera,0,0,-MouseYSpeed() Renderworld Flip Wend |
| ||
Mouse?Speed() probably the key answer here. Thanks JHOCKING. |
| ||
Don't forget to move the pointer to the center of the screen and flush it once in a while... |
| ||
While that (ie. centering the mouse pointer) certainly matters in windowed mode, does that matter in fullscreen? Just curious. |
| ||
Yes, it still matters. Even though in full screen and hidden, the mouse movement is still limited to your screen area. |
| ||
graphics3d 800,600,32 Global midw=GraphicsWidth()/2,midh=GraphicsHeight()/2 in loop... movemouse midw,midh |
| ||
I get the picture, thanks guys..screenx=640 screeny=480 Graphics3D screenx,screeny speed#=.1 HidePointer camera=CreateCamera() light=CreateLight() Dim cube(20,20) For k=0 To 19 For kk=0 To 19 cube(k,kk)=CreateCube() MoveEntity cube(k,kk),k*3,0,kk*3 EntityColor cube(k,kk),Rand(1,255),Rand(1,255),Rand(1,255) Next Next PositionEntity camera,0,10,-10 PointEntity camera,cube(10,10),0 While Not KeyDown( 1 ) xs=MouseXSpeed() ; see how far the mouse has been moved ys=MouseYSpeed() MoveMouse screenx/2,screeny/2 ;forward/backward If ys<>0 Then temp=EntityPitch(camera) RotateEntity Camera,0,EntityYaw(camera),EntityRoll(camera) MoveEntity Camera,0,0,-(ys*speed) RotateEntity Camera,temp,EntityYaw(camera),EntityRoll(camera) End If ;rotate camera toward target If xs<>0 Then TurnEntity Camera,0,-speed*xs,0 RotateEntity Camera,EntityPitch(camera),EntityYaw(camera),0 End If UpdateWorld RenderWorld Flip Wend End |