Advertisement
kemperrs

Untitled

Dec 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import camerasManager from './camerasManager';
  2.  
  3. const spectateInformation = {
  4.   entity: null,
  5.   polarAngleDeg: 0,
  6.   azimuthAngleDeg: 90,
  7.   radius: -3.5,
  8.   active: false,
  9.   startActive: false,
  10.   entityPosition: new mp.Vector3()
  11. };
  12. const localPlayer = mp.players.local;
  13.  
  14. const cam = camerasManager.getCamera('spectateCamera');
  15.  
  16. mp.events.add('render', () => {
  17.   if (!spectateInformation.active || spectateInformation.entity && (!mp.players.exists(spectateInformation.entity) || !mp.objects.exists(spectateInformation.entity))) {
  18.     return false;
  19.   }
  20.  
  21.   const coords = spectateInformation.entity.position;
  22.  
  23.   if (coords.x === 0 || coords.y === 0 || coords.z === 0) {
  24.     return false;
  25.   }
  26.  
  27.   const xMagnitude = mp.game.controls.getDisabledControlNormal(0, 1);
  28.   const yMagnitude = mp.game.controls.getDisabledControlNormal(0, 2);
  29.  
  30.   spectateInformation.polarAngleDeg = spectateInformation.polarAngleDeg + xMagnitude * 10;
  31.  
  32.   if (spectateInformation.polarAngleDeg >= 360) {
  33.     spectateInformation.polarAngleDeg = 0;
  34.   }
  35.  
  36.   if (spectateInformation.polarAngleDeg < 0) {
  37.     spectateInformation.polarAngleDeg = 360;
  38.   }
  39.  
  40.   spectateInformation.azimuthAngleDeg = spectateInformation.azimuthAngleDeg - yMagnitude * 10;
  41.  
  42.   if (spectateInformation.azimuthAngleDeg >= 160) {
  43.     spectateInformation.azimuthAngleDeg = 160;
  44.   }
  45.  
  46.   if (spectateInformation.azimuthAngleDeg < 2) {
  47.     spectateInformation.azimuthAngleDeg = 2;
  48.   }
  49.  
  50.   const polarAngleRad = spectateInformation.polarAngleDeg * Math.PI / 180.0;
  51.   const azimuthAngleRad = spectateInformation.azimuthAngleDeg * Math.PI / 180.0;
  52.  
  53.   const nextCamLocation = new mp.Vector3(
  54.     coords.x + spectateInformation.radius * (Math.sin(azimuthAngleRad) * Math.cos(polarAngleRad)),
  55.     coords.y - spectateInformation.radius * (Math.sin(azimuthAngleRad) * Math.sin(polarAngleRad)),
  56.     coords.z - spectateInformation.radius * Math.cos(azimuthAngleRad)
  57.   );
  58.  
  59.   const result = mp.raycasting.testPointToPoint(coords, nextCamLocation, spectateInformation.entity, null);
  60.  
  61.   if (typeof result !== 'undefined') {
  62.       cam.setCoord(result.position.x + result.surfaceNormal.x * 0.2, result.position.y + result.surfaceNormal.y * 0.2, result.position.z + result.surfaceNormal.z * 0.2);
  63.     } else {
  64.       cam.setCoord(nextCamLocation.x, nextCamLocation.y, nextCamLocation.z);
  65.     }
  66.  
  67.     cam.pointAt(spectateInformation.entity.handle, 0, 0, 0, true);
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement