Using mouse to look around....
Blitz3D Forums/Blitz3D Programming/Using mouse to look around....
| ||
This might sound a bit dumb, but I'm just fiddling around with Blitz3D and don't really know much :) I have a landscape working and I can run around it with the keyboard, but I want to use the mouse to 'point' at where I'm going, both left and right and up and down. The up/down movement seems fine, but when I move left and right, it DOES move left/right but it also tilts the camera. Why? I thought yaw movement would only swivel left/right. Here's the code I'm using. TurnEntity camera, 0, -MouseXSpeed() ,0 TurnEntity camera, MouseYSpeed() ,0, 0 ; Centre mouse. MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 I assume I'm doing something really dumb :) |
| ||
TurnEntity, by default, works relative to the entity's current orientation. If you think of your head as the camera then your eyes point in the Z+ direction. The Y-axis points through the top of you head. Tilt your head to look down, and then turn around your Y-axis. The problem is apparent. You need to tell TurnEntity to turn around the *world* Y-axis. TurnEntity camera, 0,YawAmount,0, True |
| ||
Thanks for that, I understand the theory now. Unfortunately, when I add the 'true' on the end, it's still the same. Reading the help file for rotateentity, it says that adding 'true' would basically rotate it around 0,0,0, but it still seems to be just turning around it's own axis. If I tilt my 'head' forward, then to the left, it basically 'rolls' the world because it still seems to be turning around my heads own y axis. Any ideas? |
| ||
have a pivot and parent the camera to it, then apply yaw turning to the pivot and apply x axis turning to the camera. |
| ||
Ok, could you give me an example? I'm not sure how to do that. |
| ||
2Pivots One CamCamPiv1=Createpivot() CamPiv2=Createpivot(CamPiv1) cam=createcamera(camPiv2) turnentity CamPiv1,0,1,0 ;Look left/right turnentity CamPiv2,1,0,0 ;Look up/down This method wont knock off cameras orientation. That should work. |
| ||
I use this:Global Dest_xang#,Dest_yang#,cam=CreateCamera() HidePointer CameraRange cam,.1,2000 Function Docam() mxs=MouseXSpeed()/2 mys=MouseYSpeed()/2 dest_xang#=dest_xang#+mys dest_yang#=dest_yang#-mxs xang#=CurveValue#(xang#,dest_xang#,5) yang#=CurveValue#(yang#,dest_yang#,5) RotateEntity cam,xang#,yang#,0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 End Function Function CurveValue#(current#,destination#,curve) current#=current#+((destination#-current#)/curve) Return current# End Function No pivots required, although pivots are easier to understand. |