North Korea Posted July 14, 2020 Posted July 14, 2020 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?
MihaiADV Posted January 15, 2021 Posted January 15, 2021 (edited) On 10/11/2020 at 9:00 PM, fases said: anyone? - Edited November 22, 2023 by MihaiADV
jke Posted May 18, 2021 Posted May 18, 2021 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
-Andreas Posted May 20, 2021 Posted May 20, 2021 (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 May 20, 2021 by -Andreas
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now