Hello!
This seems like a problem I had a while ago, I was coding an RPG type game at the time. I wanted to be able to pan around my character from a 3rd-person viewpoint with my mouse, but I also had a GUI that would cast spells, open doors, etc.
What I did was add a flag variable that activated whenever the right mouse button was pressed down. This would run a bit of code that allowed the camera to pan around the player. However, when the button was released, the flag would lower, and normal gameplay could resume.
Implemented into your own code that you put up...
While Not KeyDown(1)
If KeyDown(32)=True Then MoveEntity sphere,1,0,0
If KeyDown(30)=True Then MoveEntity sphere,-1,0,0
If KeyDown(31)=True Then MoveEntity sphere,0,0,-0.05
If KeyDown(17)=True Then MoveEntity sphere,0,0,0.05
If KeyDown(207)=True Then MoveEntity camera,0,0,1
If KeyDown(199)=True Then MoveEntity camera,0,0,-1
If KeyDown(29)=True Then MoveEntity sphere,0,10,0
If KeyHit(57)=True Then MoveEntity sphere,0,10,0
If MouseDown(1) Then MoveEntity sphere,0,0,5
If MouseDown(3) Then MoveEntity sphere,0,0,0.5
;This code below allows panning when the Right mouse button is pressed
;---
If MouseDown(2) And panstatus%=0 Then ;Check if right mouse button is pressed down
panstatus%=1 ;Set the camera panning status to 1
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) ;Reset the mouse to the center
EndIf
If panstatus%=1;When panstatus is 1, use the mouse to rotate the camera.
mxs# = mxs# + MouseXSpeed()
mys# = mys# + MouseYSpeed()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);Keep the mouse centered...
If MouseDown(2)=False Then panstatus%=0;If right mouse button is released, free the mouse and stop panning the camera
EndIf
;---
If msx# > 90 Then mxs# = 0
If msx# < 0 Then Msx# = 90
If mys# > 45 Then mys# = 45
If mys# < -45 Then mys# = -45
RotateEntity camera,mys#,0,0
RotateEntity sphere,0,-mxs#,0
Of course, you can tweak the code to work specifically how you need it, but this is how I achieved a panning camera. There are probably better ways to go about this, but it worked for me. Maybe it could for you too!
Last edited 2012
|