RTS Camera Movement by Lazlazlaz 127th Apr 2006 12:42
|
---|
Summary RTS Camera Movement - This camera control system functions like in any professional RTS game. You move the mouse close to the edge and the screen moves, move it closer and the scre Description This code works by seeing if the mouse is close to the edge (within two different distances) this is worked out as a value relative to the screen width and height. Left and right movement is simple enough using the move camera left/right commands. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com REM Global variables to be declared before rest of program global cam_speed# = 1.0 `camera speed global cam_height# = 30 `camera's height above the terrain global mat_num = 1 `matrix number FUNCTION camera_control() if mousex()>screen width() - (screen width()/50) `slow right move camera right (cam_speed#/2) endif if mousex()<screen width()/50 `slow left move camera left (cam_speed#/2) endif if mousex()>screen width() - (screen width()/100) `fast right move camera right cam_speed# endif if mousex()< screen width()/100 `fast left move camera left cam_speed# endif if mousey()>screen height() - (screen height()/25) `slow backward cx=camera angle x() xrotate camera 0 move camera -(cam_speed#/2) xrotate camera cx endif if mousey()<screen height()/25 `slow forward cx=camera angle x() xrotate camera 0 move camera (cam_speed#/2) xrotate camera cx endif if mousey()>screen height() - (screen height()/100) `fast backward cx=camera angle x() xrotate camera 0 move camera -cam_speed# xrotate camera cx endif if mousey()<screen height()/100 `fast forward cx=camera angle x() xrotate camera 0 move camera cam_speed# xrotate camera cx endif position camera camera position x(),(get ground height(mat_num,camera position x(),camera position z())+cam_height#),camera position z() ENDFUNCTION |