Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import camerasManager from './camerasManager';
- const spectateInformation = {
- entity: null,
- polarAngleDeg: 0,
- azimuthAngleDeg: 90,
- radius: -3.5,
- active: false,
- startActive: false,
- entityPosition: new mp.Vector3()
- };
- const localPlayer = mp.players.local;
- const cam = camerasManager.getCamera('spectateCamera');
- mp.events.add('render', () => {
- if (!spectateInformation.active || spectateInformation.entity && (!mp.players.exists(spectateInformation.entity) || !mp.objects.exists(spectateInformation.entity))) {
- return false;
- }
- const coords = spectateInformation.entity.position;
- if (coords.x === 0 || coords.y === 0 || coords.z === 0) {
- return false;
- }
- const xMagnitude = mp.game.controls.getDisabledControlNormal(0, 1);
- const yMagnitude = mp.game.controls.getDisabledControlNormal(0, 2);
- spectateInformation.polarAngleDeg = spectateInformation.polarAngleDeg + xMagnitude * 10;
- if (spectateInformation.polarAngleDeg >= 360) {
- spectateInformation.polarAngleDeg = 0;
- }
- if (spectateInformation.polarAngleDeg < 0) {
- spectateInformation.polarAngleDeg = 360;
- }
- spectateInformation.azimuthAngleDeg = spectateInformation.azimuthAngleDeg - yMagnitude * 10;
- if (spectateInformation.azimuthAngleDeg >= 160) {
- spectateInformation.azimuthAngleDeg = 160;
- }
- if (spectateInformation.azimuthAngleDeg < 2) {
- spectateInformation.azimuthAngleDeg = 2;
- }
- const polarAngleRad = spectateInformation.polarAngleDeg * Math.PI / 180.0;
- const azimuthAngleRad = spectateInformation.azimuthAngleDeg * Math.PI / 180.0;
- const nextCamLocation = new mp.Vector3(
- coords.x + spectateInformation.radius * (Math.sin(azimuthAngleRad) * Math.cos(polarAngleRad)),
- coords.y - spectateInformation.radius * (Math.sin(azimuthAngleRad) * Math.sin(polarAngleRad)),
- coords.z - spectateInformation.radius * Math.cos(azimuthAngleRad)
- );
- const result = mp.raycasting.testPointToPoint(coords, nextCamLocation, spectateInformation.entity, null);
- if (typeof result !== 'undefined') {
- 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);
- } else {
- cam.setCoord(nextCamLocation.x, nextCamLocation.y, nextCamLocation.z);
- }
- cam.pointAt(spectateInformation.entity.handle, 0, 0, 0, true);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement