MouseX/Y Values are quite fond of positives...
Blitz3D Forums/Blitz3D Programming/MouseX/Y Values are quite fond of positives...
| ||
Hey everybody, So I'm working on this game, and I'm trying to get it so the camera kind of pans around the main character when you move the mouse. I'm using MouseXSpeed and MouseYSpeed (as you can see in the below code) to calculate how far to turn mr. camera, but lo and behold, my msx (MouseXSpeed) and mys (MouseYSpeed) variables dont go below 0! So it won't let me pan up or left...I've tried substituting code in the function that normally executes with negative msx and msy values, but for some reason, they stay above 0. So my Q is, WHY?!? Why won't mousexspeed and mouseyspeed go below 0? And how, oh HOW, do I fix this? And, in conclusion, thank you for reading my ramblings, please read my below code, and tell me if you can help ole Daniel out (ASAP). Thanks! ^^ Function AttackThrow(mesh) PositionEntity campiv,EntityX#(mesh),EntityY#(mesh),EntityZ#(mesh) While Not KeyHit(1) mxs=MouseXSpeed() mys=-MouseYSpeed() MoveMouse GraphicsWidth/2,GraphicsHeight/2 ; Mouse shake (total mouse movement) ;mouse_shake=Abs(((mxs+mys)/2)/1000.0) ; Destination camera angle x and y values dest_cam_yaw#=dest_cam_yaw#-mxs dest_cam_pitch#=dest_cam_pitch#+mys ; Current camera angle x and y values cam_yaw=cam_yaw+((dest_cam_yaw-cam_yaw)/5) cam_pitch=cam_pitch+((dest_cam_pitch-cam_pitch)/5) ; RotateEntity campiv,0,cam_yaw#,0 RotateEntity mesh,0,cam_yaw#,0 TranslateEntity campiv,0,cam_pitch#,0 ;PointEntity cam,campiv ;MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 PositionEntity cam,EntityX#(mesh),EntityY#(mesh),EntityZ#(mesh) RotateEntity cam,21.8014,cam_yaw#,0 MoveEntity cam,0,2,-5 TurnEntity cam,cam_pitch#*.01,0,0 If MouseHit(1) obj.obj=New obj;Create a new throwing object obj\mesh=CopyEntity(grenade);Copy the grenade mesh ScaleEntity obj\mesh,0.15,0.15,0.15 TurnEntity obj\mesh,0,EntityYaw#(mesh),0 obj\curve#=0.01;-the extra height added on obj\typ=1;1 for frag obj\dec#=0.006 PositionEntity obj\mesh,EntityX(mesh),EntityY(mesh)+MeshHeight(mesh),EntityZ(mesh) EndIf For obj.obj=Each obj MoveEntity obj\mesh,0,obj\curve#,0.26 obj\curve=obj\curve-obj\dec# Next UpdateWorld RenderWorld Color 255,255,255 Text 0,0,mxs Text 0,10,mys DrawImage sight,GraphicsWidth()/2,GraphicsHeight()/2 WaitTimer(FPStimer) Flip Wend End Function |
| ||
My codes a bit of a mess, sorry ^^ |
| ||
Mousexspeed and mouseyspeed do return negative values. eg: graphics 800,600,0,2 movemouse graphicswidth()/2,graphicsheight()/2 rubbish=mousexspeed() rubbish=mouseyspeed() ;used to reset the mousexspeed command - we don't want it returning the move to 400,300 as a valid mouse move to calculate from boxx=graphicswidth()/2 boxy=graphicsheight()/2 repeat ;get the mouse speeds x/y x=mousexspeed() y=mouseyspeed() ;reset the mouse position movemouse graphicswidth()/2,graphicsheight()/2 ;get the change in mouse position immediately after and discard rubbish=mousexspeed() rubbish=mouseyspeed() ;used to reset the mousexspeed command - we don't want it returning the move to 400,300 as a valid mouse move to calculate from cls text 0,15,x text 0,30,y boxx=boxx+x boxy=boxy+y rect boxx-4,boxy-4,8,8,1 flip until keydown(1) just wrote that then, don't have blitz installed on this machine but it should work. |
| ||
Yep, they do return negative values when the mouse has been moved left or up. At least they used to - I don't know which version of Blitz you're using, nor do I have any version installed to test on. Last time I used it was probably 1.92 or something. |
| ||
huh...thats weird...they still aren't returning negative with me...at the bottom of my code I put Text 0,0,mxs Text 0,10,mys and it shows that they don't go below 0...I have Blitz3D v1.1... In another function, right above it in my main code, it returns negative values, but this function doesn't...does anyone have any idea why it's all actin up on me? |
| ||
Ha, ok, lemme explain a little more. I have quite a few functions in my code, and the function thats giving me trouble is relating to attacking. You move the mouse, which turns the camera, so you can target an enemy and punch him. Thats in 3rd person view. I have a function directly above that in the code, and this one is for another type of attacking method, a first-person shooter kinda thing. The MouseX/YSpeed variables work perfectly in that function, but I bring it down to this one, and they dont go below 0. And get this-I copied-and-pasted the ENTIRE camera pan section of the working function INTO the non-working function, and it didn't work!! Exact same code snippet, just brought down to the next one, and it didn't work!!! o.O |
| ||
Here is a common function I often throw in to do simple camera navigation using the mouse. This works fine for me:Function Navigate_World_With_MouseAndKeys(turnSpeed#=1, moveSpeed#=1) Local dY# = EntityPitch(GlobalCamera)+MouseYSpeed()/2*turnSpeed If dY > 89 Then dY = 89 If dY < -89 Then dY = -89 Local dz# = (KeyDown(200)-KeyDown(208)) * moveSpeed Local dx# = (KeyDown(205)-KeyDown(203)) * moveSpeed If dz <> 0 And dx <> 0 Then dx=dx * 0.707 dz=dz * 0.707 End If RotateEntity GlobalCamera, dY, EntityYaw(GlobalCamera)-(MouseXSpeed()/2)*turnSpeed, 0 MoveEntity GlobalCamera, dx, 0, dz MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 If KeyHit(4) Then CameraZoom GlobalCamera, 4.0 End If If KeyHit(5) Then CameraZoom GlobalCamera, 1.0 End If End Function |
| ||
oh boy, sorry to cause you guys so much trouble. I went thru my code, and changed GraphicsWidth/2 to GraphicsWidth()/2 (likewise for GraphicsHeight) and it worked ^^ sorry guys, thnx for all your help, I can't believe this simple a solution escaped my cranium =) haha |
| ||
Yea, dontcha just hate those ()'s. I think you only need them if the function/command returns a value though. Like with PositionEntity entity,0,0,0 Doesn't need the () to work but... MouseX() Does |