Overkillz Posted October 26, 2019 Share Posted October 26, 2019 (edited) Hello dear community. Im having a big issue with setCameraMatrix on the clientside. Well, I needed to set a custom camera target to an object (This script is an adaptation of @Sasu) Spoiler local rotX, rotY, rotRadius, maxRadius = 0, -math.pi/2, 10, 20 local isCustomCamera = false local cameraTarget = nil local sX, sY = guiGetScreenSize() addEventHandler("onClientPreRender", root, function() if isCustomCamera and isElement(cameraTarget) then local x, y, z = getElementPosition( cameraTarget ) local cx, cy, cz cx = x + rotRadius * math.sin(rotY) * math.cos(rotX) cy = y + rotRadius * math.sin(rotY) * math.sin(rotX) cz = z + rotRadius * math.cos(rotY) local hit, hitX, hitY, hitZ = processLineOfSight(x, y, z, cx, cy, cz, _, false, _, _, _, _, _, _, cameraTarget) if hit then cx, cy, cz = hitX, hitY, hitZ end setCameraMatrix( cx, cy, cz, x, y, z ) end end ) addEventHandler("onClientKey", root, function(button) if button == "mouse_wheel_up" then rotRadius = math.max(2, rotRadius - 1) elseif button == "mouse_wheel_down" then rotRadius = math.min(maxRadius, rotRadius + 1) end end ) addEventHandler("onClientCursorMove", root, function(cX,cY,aX,aY) if isCursorShowing() or isMTAWindowActive() then return end aX = aX - sX/2 aY = aY - sY/2 rotX = rotX - aX * 0.01745 * 0.3 rotY = math.min(-0.02, math.max( rotY + aY * 0.01745 * 0.3, -3.11 ) ) end ) function setCustomCameraTarget(element) if isElement(element) then cameraTarget = element isCustomCamera = true return true else cameraTarget = nil isCustomCamera = false end end Well, my problem is that when Im using that custom camera target and I want to restore the camera to the player. It doesn't work. I tried several ways and events like onClientRender, onClientPreRender ... I tried to spawn again the player, setCameraTarget (The default one) and later use the setCameraMatrix and to re-force it. add the setCameraMatrix inside a function handled by onClientRender. Before I've used setCameraMatrix I removed the events used for the custom camera target and set the varaibles (cameraTarget & isCustomCamera) as nil & false. I hope you can bring me a hand with this issue. Any information that u need just comment below and I will bring you more details. Best regards. Edited October 26, 2019 by Overkillz Link to comment
Mirage2287 Posted October 28, 2019 Share Posted October 28, 2019 function setCustomCameraTarget(element) if isElement(element) then cameraTarget = element isCustomCamera = true return true else cameraTarget = nil isCustomCamera = false setCameraTarget(localPlayer) -- Is this what you mean? end end Link to comment
Overkillz Posted October 28, 2019 Author Share Posted October 28, 2019 Yes, but it is not working. Idk if there are other ways to simulate or force the function setCameraMatrix. Might attaching a cam, but Im not sure if you know how to deal with this weird issue. Regards. Link to comment
Moderators IIYAMA Posted October 29, 2019 Moderators Share Posted October 29, 2019 22 hours ago, Overkillz said: Yes, but it is not working. Idk if there are other ways to simulate or force the function setCameraMatrix. Might attaching a cam, but Im not sure if you know how to deal with this weird issue. Regards. The issue is caused by not keeping an eye on state changing. The camera status can be changed by resources, but also by MTA conditions (for example dying). If you want to force setCameraMatrix you will need to repeat that process every frame to prevent any interruption. So you could create a resource which will manage all camera statuses and prevent any interruption. And even add extra custom ones. Like moving a camera from position to position.(cinematic effect) Link to comment
Overkillz Posted October 30, 2019 Author Share Posted October 30, 2019 @IIYAMA Thanks for your answer, but I didn't get u at all. Sorry Practically Im managing the camera by a single resource. I will tell you step by step what do I do ? The fisrt thing I do is join to the arena, in this case is the garage arena. Inside the arena I only do is to spawn the player and setCameraTarget. Later use the custom camera script aimming to a vehicle. When I leave the arena (I try to set the Default MTA Camera using setCameraTarget) In this case it doesn't work, so I kill the player, spawn it again and set again the default mta camera. Obyously I have removed the custom camera events and restore the varaibles previously but nothing. As I said before, even using onClientPreRender, onClientRender or whatever the camera doesn't work. Thanks for reading and best Regards. Link to comment
Moderators IIYAMA Posted October 30, 2019 Moderators Share Posted October 30, 2019 1 hour ago, Overkillz said: Later use the custom camera script aimming to a vehicle. Which methods/implementations are use for that? Link to comment
Overkillz Posted October 30, 2019 Author Share Posted October 30, 2019 @IIYAMA This one. Just using the function setCustomCameraTarget(theElement) local rotX, rotY, rotRadius, maxRadius = 0, -math.pi/2, 10, 20 local isCustomCamera = false local cameraTarget = nil local sX, sY = guiGetScreenSize() addEventHandler("onClientPreRender", root, function() if isCustomCamera and isElement(cameraTarget) then local x, y, z = getElementPosition( cameraTarget ) local cx, cy, cz cx = x + rotRadius * math.sin(rotY) * math.cos(rotX) cy = y + rotRadius * math.sin(rotY) * math.sin(rotX) cz = z + rotRadius * math.cos(rotY) local hit, hitX, hitY, hitZ = processLineOfSight(x, y, z, cx, cy, cz, _, false, _, _, _, _, _, _, cameraTarget) if hit then cx, cy, cz = hitX, hitY, hitZ end setCameraMatrix( cx, cy, cz, x, y, z ) end end ) addEventHandler("onClientKey", root, function(button) if button == "mouse_wheel_up" then rotRadius = math.max(2, rotRadius - 1) elseif button == "mouse_wheel_down" then rotRadius = math.min(maxRadius, rotRadius + 1) end end ) addEventHandler("onClientCursorMove", root, function(cX,cY,aX,aY) if isCursorShowing() or isMTAWindowActive() then return end aX = aX - sX/2 aY = aY - sY/2 rotX = rotX - aX * 0.01745 * 0.3 rotY = math.min(-0.02, math.max( rotY + aY * 0.01745 * 0.3, -3.11 ) ) end ) function setCustomCameraTarget(element) if isElement(element) then cameraTarget = element isCustomCamera = true return true else cameraTarget = nil isCustomCamera = false end end Link to comment
Moderators IIYAMA Posted October 30, 2019 Moderators Share Posted October 30, 2019 8 minutes ago, Overkillz said: This one. So you did this clientside: setCustomCameraTarget() On serverside you did this: setCameraTarget(player, player) What is the delay between those two actions? Did you try to apply them after each other with a delay of 2 seconds? Link to comment
Overkillz Posted October 30, 2019 Author Share Posted October 30, 2019 (edited) I tried it. After leaving the arena I did this setTimer(triggerServerEvent,2000,1,"onForceSpawnLobbyPlayer",localPlayer) And serverside function forceSpawnLobbyPlayer() outputChatBox("Forcing Camera Matrix") spawnPlayer(source, 0, 0, 5, 90, 0,0, 30) setElementFrozen(source,true) setCameraTarget(source,source) setCameraMatrix(source,488.32220458984,-1607.4827880859,37.201072692871,399.98428344727,-1560.7738037109,41.033145904541) end addEvent("onForceSpawnLobbyPlayer",true) addEventHandler( "onForceSpawnLobbyPlayer",getRootElement(),forceSpawnLobbyPlayer) It is executed, but nothing. Im still not getting the camera player. Edited October 30, 2019 by Overkillz Link to comment
Moderators IIYAMA Posted October 30, 2019 Moderators Share Posted October 30, 2019 17 minutes ago, Overkillz said: It is executed, but nothing. I still not getting the camera player. I see line 6 cancelling line 5? There is absolutely no logic in that. 21 minutes ago, Overkillz said: After leaving the arena I did this Did you call this function before you did that? (to put a stop to the rendering process) setCustomCameraTarget() Link to comment
Overkillz Posted October 30, 2019 Author Share Posted October 30, 2019 How that it is cancelling. Im just doing setCameraTarget just to 'lets say Restore' the default MTA Camera to later apply the camera Matrix. Do I need to restore the camera player fully before I apply the cameraatrix to a specific position ? And yes, Im executing this function before execute the previous one mentioned. setCustomCameraTarget() Link to comment
Moderators IIYAMA Posted October 30, 2019 Moderators Share Posted October 30, 2019 3 minutes ago, Overkillz said: Do I need to restore the camera player fully before I apply the cameraatrix to a specific position ? No, but you might need to apply a delay between line 5 and 6, if you think it is necessary. Link to comment
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