Jump to content

Recommended Posts

Posted

I have created a camera to spectate players and I would like to add that you can move the camera around with your mouse as you normally would.
This is my code so far:
 

       

int camera;

public void StartSpectate(object[] args)
{
            Player target = Entities.Players.All.First(p => p.RemoteId == (ushort)Convert.ToUInt32(args[0]));
            Player.LocalPlayer.FreezePosition(true);


            camera = RAGE.Game.Cam.CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", target.Position.X, target.Position.Y, target.Position.Z, 0f, 0f, 0f, 40f, false, 0);
            RAGE.Game.Cam.SetCamActive(camera, true);
            RAGE.Game.Cam.RenderScriptCams(true, false, 0, false, true, 0);
            RAGE.Game.Cam.AttachCamToEntity(camera, target.Handle, 0f, -7.5f, 2.5f, true);
            RAGE.Game.Cam.PointCamAtEntity(camera, target.Handle, 0f, 0f, 0f, true);
            RAGE.Game.Entity.AttachEntityToEntity(Player.LocalPlayer.Handle, target.Handle, 0, 0f, 0f, 5f, 0f, 0f, 0f, true, false, false, false, 0, false);
        }

Any ideas?

  • 2 months later...
  • 3 months later...
  • 4 months later...
Posted
On 7/14/2020 at 1:40 PM, North Korea said:

I have created a camera to spectate players and I would like to add that you can move the camera around with your mouse as you normally would.
This is my code so far:
 

       


int camera;

public void StartSpectate(object[] args)
{
            Player target = Entities.Players.All.First(p => p.RemoteId == (ushort)Convert.ToUInt32(args[0]));
            Player.LocalPlayer.FreezePosition(true);


            camera = RAGE.Game.Cam.CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", target.Position.X, target.Position.Y, target.Position.Z, 0f, 0f, 0f, 40f, false, 0);
            RAGE.Game.Cam.SetCamActive(camera, true);
            RAGE.Game.Cam.RenderScriptCams(true, false, 0, false, true, 0);
            RAGE.Game.Cam.AttachCamToEntity(camera, target.Handle, 0f, -7.5f, 2.5f, true);
            RAGE.Game.Cam.PointCamAtEntity(camera, target.Handle, 0f, 0f, 0f, true);
            RAGE.Game.Entity.AttachEntityToEntity(Player.LocalPlayer.Handle, target.Handle, 0, 0f, 0f, 5f, 0f, 0f, 0f, true, false, false, false, 0, false);
        }

Any ideas?

Hi there would you like to share this code with me if its done? discord: jke#9614

Posted (edited)

Here's a client-side JavaScript version you can re-write for C#. It's a modified script I found sometime on the Discord I think, by root. But I'm not sure. Anyway, translating it into a C# equivalent wont be difficult.
 

/* Camera object */
let camObj = null;

/* Camera settings */
const mouseSensitivity = 2.5;
const zoomSpeed = 1.5;
const minZoom = 5.0;
const maxZoom = 60.0;

mp.events.add('render', () => {
	if (camObj !== null && camObj.isActive() && camObj.isRendering()) {
        mp.game.controls.disableAllControlActions(2);

        let x = (mp.game.controls.getDisabledControlNormal(7, 1) * mouseSensitivity);
        let y = (mp.game.controls.getDisabledControlNormal(7, 2) * mouseSensitivity);
        let zoomIn = (mp.game.controls.getDisabledControlNormal(2, 40) * zoomSpeed);
        let zoomOut = (mp.game.controls.getDisabledControlNormal(2, 41) * zoomSpeed);

        let currentRot = camObj.getRot(2);

        currentRot = new mp.Vector3(currentRot.x - y, 0, currentRot.z - x);

        camObj.setRot(currentRot.x, currentRot.y, currentRot.z, 2);

        if (zoomIn > 0)
        {
            let currentFov = camObj.getFov();
            currentFov -= zoomIn;
            if (currentFov < minZoom)
                currentFov = minZoom;
            camObj.setFov(currentFov);
        } else if (zoomOut > 0)
        {
            let currentFov = camObj.getFov();
            currentFov += zoomOut;
            if (currentFov > maxZoom)
                currentFov = maxZoom;
            camObj.setFov(currentFov);
        }
    }
});

 

Edited by -Andreas

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...