Advertisement
Lorenc

Class Selection Camera movement

Oct 21st, 2011
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.46 KB | None | 0 0
  1. /*
  2.  *
  3.  *
  4.  *
  5.  *
  6.  *
  7.  *
  8. */
  9.  
  10. #include                        <a_samp>
  11.  
  12. /* ** Server Data ** */
  13. const
  14.     Float: spawnX = 0.0,     // The SPAWN X you're willing to work from
  15.     Float: spawnY = 0.0,     // The SPAWN Y you're willing to work from
  16.     Float: spawnZ = 5.0,     // The SPAWN Y you're willing to work from
  17.     Float: camRadius = 20.0, // The radius of the camera rotating
  18.     Float: camSpeed  = 1.25, // The speed of the camera moving around. MUST NOT BE NULL; IT WONT MOVE IF SO!
  19.     Float: camHeight = 6.0   // The height of the camera once moving!
  20. ;
  21.  
  22. /* ** Player Data ** */
  23. new
  24.     prc_Timer                   [MAX_PLAYERS],  // The timer for the movement.
  25.     bool: prc_Moving            [MAX_PLAYERS],  // Check if the player is moving his camera
  26.     Float: prc_Degree           [MAX_PLAYERS]   // The degree counter to show which the player is on.
  27. ;
  28.  
  29. forward MoveCamera(playerid);
  30.  
  31. main() { }
  32.  
  33. public OnGameModeInit()
  34. {
  35.     SetGameModeText("RotationCamera test");
  36.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  37.     return 1;
  38. }
  39.  
  40. public OnGameModeExit()
  41.     return 1;
  42.  
  43.  
  44. public OnPlayerRequestClass(playerid, classid)
  45. {
  46.     SetPlayerPos(playerid, spawnX, spawnY, spawnZ);
  47.    
  48.     if(prc_Moving[playerid] == false) // Check whether the camera is already set.
  49.     {
  50.         prc_Degree[playerid] = 0; // Reseting the variable
  51.         prc_Timer[playerid] = SetTimerEx("MoveCamera", 75, true, "d", playerid); // Setting the timer
  52.         prc_Moving[playerid] = true; // okay, now we're going to activate the moving variable
  53.     }
  54.     return 1;
  55. }
  56.  
  57. public MoveCamera(playerid) // The core of the movement
  58. {
  59.     static // Static for the repeation :O
  60.         Float: nX,  // The newX
  61.         Float: nY   // the newY
  62.     ;
  63.     if(prc_Moving[playerid] == false) // check whether the timer is activated and the variable isn't.
  64.     {
  65.         KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
  66.         prc_Degree[playerid] = 0; // Reseting the variable
  67.     }
  68.     if(prc_Degree[playerid] >= 360) prc_Degree[playerid] = 0; // If the rotation is past 360, reset to 0 (looks more neater)
  69.     prc_Degree[playerid] += camSpeed; // For some smooth rotation, I'm using 1.25
  70.    
  71.     nX = spawnX + camRadius * floatcos(prc_Degree[playerid], degrees);
  72.     nY = spawnY + camRadius * floatsin(prc_Degree[playerid], degrees);
  73.    
  74.     // So, we're going to get the spawn axis and add the radius in to them.
  75.     // Then we use the trignometric functions to apply such angles to the movement
  76.     // making it look nice.
  77.     SetPlayerCameraPos(playerid, nX, nY, spawnZ + camHeight); // Setting the Camera position around the player
  78.     SetPlayerCameraLookAt(playerid, spawnX, spawnY, spawnZ); // Looking at the player position from there :)
  79.     SetPlayerFacingAngle(playerid, prc_Degree[playerid] - 90.0); // to make it face the camera :)
  80.     return 1;
  81. }
  82.  
  83. public OnPlayerDisconnect(playerid, reason)
  84. {
  85.     if(prc_Moving[playerid] == true)
  86.     {
  87.         KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
  88.         prc_Degree[playerid] = 0; // Reseting the variable
  89.         prc_Moving[playerid] = false; // Reseting the variable
  90.     }
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerSpawn(playerid)
  95. {
  96.     if(prc_Moving[playerid] == true)
  97.     {
  98.         KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running.
  99.         prc_Degree[playerid] = 0; // Reseting the variable
  100.         prc_Moving[playerid] = false; // Reseting the variable
  101.         SetCameraBehindPlayer(playerid); // Preventing bugs from appearing.
  102.     }
  103.     return 1;
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement