Search the Community
Showing results for tags 'camera'.
-
hi guys I created a reporter camera but it has a problem When the person holding the camera turns, the camera does not turn with the person this is my code ``` x,y,z = getElementPosition(localPlayer) local camera = createObject(367,x, y, z) function updatePed() setElementBoneRotation(localPlayer,22,0, -60, 0) setElementBoneRotation(localPlayer,23,90, -100, 80) setElementBoneRotation(localPlayer,24,80, 30, 0) setElementBoneRotation(localPlayer,32,0, -85, 10) setElementBoneRotation(localPlayer,33,-70, -108, -30) updateElementRpHAnim (localPlayer) addEventHandler ("onClientPedsProcessed", getRootElement(), updatePed) end addCommandHandler("setanim1",updatePed) function dadancamera() setElementData(camera,"startlive",true) triggerServerEvent("messagelive",root) exports.bone_attach:attachElementToBone(camera,localPlayer,1, 0.15, 0.25, -0.1, 0, 0, 90) end addCommandHandler("setanim1",dadancamera) function updatePed2() removeEventHandler("onClientPedsProcessed", getRootElement(), updatePed) destroyElement(camera) end addCommandHandler("setanim2",updatePed2) function didanlive() if getElementData(camera,"startlive") == true then addEventHandler ( "onClientRender", root, didanlive ) x,y,z = getElementPosition(localPlayer) x2,y2,z2 = getElementPosition(camera) x4,y4,z4 = getElementRotation(camera) x3,y3,z3 = getElementRotation(localPlayer) setCameraMatrix(x2,y2,z2,x,y,z2,0,0) end end addCommandHandler("live",didanlive) function camset() setCameraTarget(localPlayer) removeEventHandler ( "onClientRender", root, didanlive ) end addCommandHandler("ended",camset) ```
-
How to make a camera Shake if vehicle speed 300+ km/h? Как сделать тряску камеры если скорость машины свыше 300 км.ч?
-
Any ideas how can I calculate the camera perspective's 4 corners into a flat 2D map? Here's what the camera should see: And here is what should it look like from the outside: I need to calculate the 4 points position
-
So if i using function "setCameraMatrix" then i can't rotation it. For example i want set camera in one point and turn it 90 degrees in left but i can't pls help! function DropCamera(player, command) local x, y, z = getElementPosition(player) setCameraMatrix(player, x, y, z+1.5, 0, 0, 90, 0, 0) end addCommandHandler("setcamera", DropCamera)
- 1 reply
-
- mta
- gta san andreas
- (and 5 more)
-
I'm daring myself to add more little things to the tutorials shown here. It's of great pleasure to announce that the following code works. I know it is not much, but it's one more step closer to my dream server. So, function joinHandler() spawnPlayer(source, 2023, 1008, 10.83, -90, math.random (1,288)) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("¡Bienvenido!", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) You can skip the spanish words. The result is as expected: when the player joins, the chatbox shows the text, the player is looking at the east, and the skin is randomized between 1 and 288. However, the camera is aiming at its default value: 0. The result has a rather inconvenient detail: the camera is looking at the right side of the character's body. UPDATE: I added setPedCameraRotation. There are no errors being detected, but the camera is not changing at all. function joinHandler() spawnPlayer(source, 2023, 1008, 10.83, -90, math.random (1,288)) fadeCamera(source, true) setCameraTarget(source, source) setPedCameraRotation(source, 90) outputChatBox("¡Bienvenido!", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) How can I modify where the camera is looking at when a player joins, so that way it looks at the same place the character is looking?
-
Estou com uma dúvida um tanto quanto pertinente. Quando faço um teleporte por maker por exemplo para um interior, quando o player é teleportado a câmera ao invés de ficar nas costas dele fica ao lado. Como faço para resolver ? PS: Já tentei o "setCameraTarget". Segue print abaixo para maiores detalhes: https://i.imgur.com/ClGFMrq.png
-
I'm working on a type of RTS camera style and I encounter a problem. The camera can rotate on the same axis without problem, it can zoom and thats about it, but it needed to be looking at an element. Now I'm working on a freecam mode where by getting to the edges of the screen you can move to north, east, west or south. It is easy when the camera rotation is 0, because you know that the top of the screen will be allways X cardinal position, it looked something like this: local camSpeed = 0.2 local sx, sy = getCursorPosition() local x, y, z = getElementPosition(camElement) if sy == 0 then -- top setElementPosition(camElement, x, y-camSpeed, z) end if sy == 1 then -- down setElementPosition(camElement, x, y+camSpeed, z) end if sx == 0 then -- left setElementPosition(camElement, x+camSpeed, y, z) end if sx == 1 then -- right setElementPosition(camElement, x-camSpeed, y, z) end As I said, this works fine while my rotation is 0, but when I move to something like 180º, my now top of the screen will not go to the south but rather north, so it would move like my mouse was on the bottom of the screen. The question here is if there is a algorithm that i can use to determinate how much of X and how much of Y i need to add to the position of my camElement in order to go "up" or "down"... If you didn't get what I want yet, think of The Sims 3 for example, when you put your mouse on the top of your screen you go up, whatever your rotation is, it doesn't matter, you will always go up. With the code I have I can only go UP if im facing South, on the other hand if im facing North then when my mouse is on the TOP i will go DOWN instead of UP. Hope you can help me with this one, and thanks!
-
Is there any way to zoom with the camera (like with the sniper scope)? I want to change the camera FOV for an attached camera. Thanks
- 2 replies
-
- setcamerafieldofview
- fov
-
(and 2 more)
Tagged with:
-
Hello! I've made a login panel. After the player logs in, he'll need to select which character he wanna play with. At this point, the player see the selected character in gta world (interior: 0) and a window with his characters. Because if it's interior 0, I want to make only the local player see that character in the world, how is that possible if I can't set the camera's dimension?
-
Hello dear reader! A few days ago i'm tried to make the Object Editor by XYZ Axle by cursor. But when i'm rotate camera to other side, like Y axle and i'm try to move X axle gets fail. I dont know how to get this perfect. Demonstration image: (red - X axle; green - Y axle; blue - Z axle) The code: local screenX, screenY = guiGetScreenSize() local editorFont = dxCreateFont("files/fonts/Roboto.ttf", 8, false, "antialiased") local editorTable = nil local editorMenu = { {"move", "Move"}, {"rotate", "Rotate"}, {"scale", "Scale"}, {"save", "Save"} } local iconSize = 16 local iconHalfSize = iconSize / 2 local axisLineThickness = 1.5 local editorColors = { axisX = {200, 50, 60}, axisY = {50, 200, 60}, axisZ = {50, 60, 200}, activeMode = {255, 150, 0}, inactiveMode = {255, 255, 255} } bindKey("F4", "down", -- Editor test function () local x, y, z = getElementPosition(localPlayer) local obj = createObject(2867, x, y, z) setElementCollisionsEnabled(obj, false) attachElements(obj, localPlayer, 0, 0, 0, 0, 0, 0) toggleEditor(obj, false) end ) addEventHandler("onClientRender", getRootElement(), function () if not editorTable then return end local absX, absY = 0, 0 if isCursorShowing() then if not isMTAWindowActive() then local relX, relY = getCursorPosition() absX, absY = relX * screenX, relY * screenY end end local elementX, elementY, elementZ = getElementPosition(editorTable["element"]) local startX, startY = getScreenFromWorldPosition(elementX, elementY, elementZ, 128) local xX, xY, xZ = getPositionFromElementOffset(editorTable["element"], editorTable["elementRadius"], 0, 0) local yX, yY, yZ = getPositionFromElementOffset(editorTable["element"], 0, editorTable["elementRadius"], 0) local zX, zY, zZ = getPositionFromElementOffset(editorTable["element"], 0, 0, editorTable["elementRadius"]) endXX, endXY = getScreenFromWorldPosition(xX, xY, xZ, 128) endYX, endYY = getScreenFromWorldPosition(yX, yY, yZ, 128) endZX, endZY = getScreenFromWorldPosition(zX, zY, zZ, 128) if not endXX or not endYX or not endZX or not endXY or not endYY or not endZY then return end dxDrawLine(startX, startY, endXX, endXY, tocolor(editorColors["axisX"][1], editorColors["axisX"][2], editorColors["axisX"][3], 255), axisLineThickness, false) dxDrawLine(startX, startY, endYX, endYY, tocolor(editorColors["axisY"][1], editorColors["axisY"][2], editorColors["axisY"][3], 255), axisLineThickness, false) dxDrawLine(startX, startY, endZX, endZY, tocolor(editorColors["axisZ"][1], editorColors["axisZ"][2], editorColors["axisZ"][3], 255), axisLineThickness, false) dxDrawRectangle(endXX - iconHalfSize, endXY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisX"][1], editorColors["axisX"][2], editorColors["axisX"][3], 255)) dxDrawRectangle(endYX - iconHalfSize, endYY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisY"][1], editorColors["axisY"][2], editorColors["axisY"][3], 255)) dxDrawRectangle(endZX - iconHalfSize, endZY - iconHalfSize, iconSize, iconSize, tocolor(editorColors["axisZ"][1], editorColors["axisZ"][2], editorColors["axisZ"][3], 255)) dxDrawImage(endXX - iconHalfSize, endXY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") dxDrawImage(endYX - iconHalfSize, endYY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") dxDrawImage(endZX - iconHalfSize, endZY - iconHalfSize, iconSize, iconSize, "files/images/" .. editorTable["currentMode"] .. ".png") if editorTable["hoveredMenuIcon"] then editorTable["hoveredMenuIcon"] = false end if not editorTable["activeAxis"] then for i = 1, #editorMenu do local currentColor = editorColors["inactiveMode"] if editorTable["currentMode"] == editorMenu[i][1] then currentColor = editorColors["activeMode"] end local iconX = ((startX - iconHalfSize) + ((i - 1) * (iconSize + 5))) + 32 local iconY = (startY - iconHalfSize) + 32 dxDrawRectangle(iconX, iconY, iconSize, iconSize, tocolor(currentColor[1], currentColor[2], currentColor[3], 255)) dxDrawImage(iconX, iconY, iconSize, iconSize, "files/images/" .. editorMenu[i][1] .. ".png") if absX >= iconX and absX <= iconX + iconSize and absY >= iconY and absY <= iconY + iconSize then editorTable["hoveredMenuIcon"] = i end end end if editorTable["hoveredMenuIcon"] then local tooltipWidth = dxGetTextWidth(editorMenu[editorTable["hoveredMenuIcon"]][2], 1.0, editorFont) + 10 local tooltipHeight = dxGetFontHeight(1.0, editorFont) + 10 dxDrawRectangle(absX + 10, absY, tooltipWidth, tooltipHeight, tocolor(0, 0, 0, 200)) dxDrawText(editorMenu[editorTable["hoveredMenuIcon"]][2], absX + 10, absY, absX + 10 + tooltipWidth, absY + tooltipHeight, tocolor(255, 255, 255, 255), 1.0, editorFont, "center", "center") if getKeyState("mouse1") then local hoveredMenuIcon = editorMenu[editorTable["hoveredMenuIcon"]][1] if editorTable["currentMode"] ~= hoveredMenuIcon then if hoveredMenuIcon ~= "save" then editorTable["currentMode"] = hoveredMenuIcon else saveEditorElementChanges() end end end end if editorTable and editorTable["hoveredMode"] then editorTable["hoveredMode"] = false end if absX >= endXX - iconHalfSize and absX <= endXX - iconHalfSize + iconSize and absY >= endXY - iconHalfSize and absY <= endXY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "X" elseif absX >= endYX - iconHalfSize and absX <= endYX - iconHalfSize + iconSize and absY >= endYY - iconHalfSize and absY <= endYY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "Y" elseif absX >= endZX - iconHalfSize and absX <= endZX - iconHalfSize + iconSize and absY >= endZY - iconHalfSize and absY <= endZY - iconHalfSize + iconSize then editorTable["hoveredMode"] = "Z" end -- OBJECT MOVE BY AXLES/CURSOR if editorTable and editorTable["activeAxis"] then if isCursorShowing() and getKeyState("mouse1") then local relX, relY = getCursorPosition() local cameraRotation = getCameraRotation() local elementX, elementY, elementZ = 0, 0, 0 local elementRX, elementRY, elementRZ = 0, 0, 0 local elementSX, elementSY, elementSZ = 0, 0, 0 if isElementAttached(editorTable["element"]) then elementX, elementY, elementZ, elementRX, elementRY, elementRZ = getElementAttachedOffsets(editorTable["element"]) local attachedElementRX, attachedElementRY, attachedElementRZ = getElementRotation(getElementAttachedTo(editorTable["element"])) cameraRotation = cameraRotation + attachedElementRZ else elementX, elementY, elementZ = getElementPosition(editorTable["element"]) elementRX, elementRY, elementRZ = getElementRotation(editorTable["element"]) end if getElementType(editorTable["element"]) == "object" then elementSX, elementSY, elementSZ = getObjectScale(editorTable["element"]) end if editorTable["currentMode"] == "move" then if editorTable["activeAxis"] == "X" then elementX = getInFrontOf(elementX, false, -(cameraRotation + 90), ((relX - 0.5) * 5)) elseif editorTable["activeAxis"] == "Y" then elementY = getInFrontOf(false, elementY, -cameraRotation, -((relY - 0.5) * 5)) elseif editorTable["activeAxis"] == "Z" then elementZ = elementZ - ((relY - 0.5) * 5) end elseif editorTable["currentMode"] == "rotate" then if editorTable["activeAxis"] == "X" then elementRX = getInFrontOf(elementRX, false, -(cameraRotation + 90), ((relY - 0.5) * 15)) elseif editorTable["activeAxis"] == "Y" then elementRY = getInFrontOf(false, elementRY, -cameraRotation, ((relX - 0.5) * 15)) elseif editorTable["activeAxis"] == "Z" then elementRZ = getInFrontOf(elementRZ, false, -(cameraRotation + 90), -((relX - 0.5) * 15)) end elseif editorTable["currentMode"] == "scale" then if editorTable["activeAxis"] == "X" then elementSX = getInFrontOf(elementSX, false, -(cameraRotation + 90), ((relX - 0.5) * 5)) elseif editorTable["activeAxis"] == "Y" then elementSY = getInFrontOf(false, elementSY, -cameraRotation, ((relY - 0.5) * 5)) elseif editorTable["activeAxis"] == "Z" then elementSZ = elementSZ - ((relY - 0.5) * 5) end end if isElementAttached(editorTable["element"]) then setElementAttachedOffsets(editorTable["element"], elementX, elementY, elementZ, elementRX, elementRY, elementRZ) else setElementPosition(editorTable["element"], elementX, elementY, elementZ) setElementRotation(editorTable["element"], elementRX, elementRY, elementRZ) end if getElementType(editorTable["element"]) == "object" then elementSX = math.max(0.25, math.min(3.0, elementSX)) elementSY = math.max(0.25, math.min(3.0, elementSY)) elementSZ = math.max(0.25, math.min(3.0, elementSZ)) setObjectScale(editorTable["element"], elementSX, elementSY, elementSZ) end setCursorPosition(screenX / 2, screenY / 2) setCursorAlpha(0) else if editorTable["activeAxis"] then editorTable["activeAxis"] = false setCursorAlpha(255) end end end end ) addEventHandler("onClientClick", getRootElement(), function (button, state, absX, absY) if not editorTable then return end if button == "left" then if state == "down" then if editorTable["hoveredMode"] then setCursorPosition(screenX / 2, screenY / 2) setCursorAlpha(0) editorTable["activeAxis"] = editorTable["hoveredMode"] end elseif state == "up" then local oldActiveAxis = editorTable["activeAxis"] if oldActiveAxis then editorTable["activeAxis"] = false if oldActiveAxis == "X" then setCursorPosition(endXX, endXY) elseif oldActiveAxis == "Y" then setCursorPosition(endYX, endYY) elseif oldActiveAxis == "Z" then setCursorPosition(endZX, endZY) end setCursorAlpha(255) end end end end ) function toggleEditor(element, saveFunction, ...) if element then editorTable = { element = element, elementRadius = getElementRadius(element) * 1.25, saveFunction = saveFunction, others = {...}, currentMode = "move", hoveredMode = false, hoveredMenuIcon = false, activeAxis = false, } else editorTable = nil setCursorAlpha(255) end end function saveEditorElementChanges() if not editorTable then return end if not editorTable["element"] or not isElement(editorTable["element"]) then return end if editorTable["saveFunction"] then if isElementAttached(editorTable["element"]) then local x, y, z, rx, ry, rz = getElementAttachedOffsets(editorTable["element"]) triggerEvent(editorTable["saveFunction"], localPlayer, {{x, y, z}, {rx, ry, rz}, {getObjectScale(editorTable["element"])}}, unpack(editorTable["others"])) else triggerEvent(editorTable["saveFunction"], localPlayer, {{getElementPosition(editorTable["element"])}, {getElementRotation(editorTable["element"])}, {getObjectScale(editorTable["element"])}}, unpack(editorTable["others"])) end end toggleEditor(false) end function getPositionFromElementOffset(element, offsetX, offsetY, offsetZ) local elementMatrix = getElementMatrix(element, false) local elementX = offsetX * elementMatrix[1][1] + offsetY * elementMatrix[2][1] + offsetZ * elementMatrix[3][1] + elementMatrix[4][1] local elementY = offsetX * elementMatrix[1][2] + offsetY * elementMatrix[2][2] + offsetZ * elementMatrix[3][2] + elementMatrix[4][2] local elementZ = offsetX * elementMatrix[1][3] + offsetY * elementMatrix[2][3] + offsetZ * elementMatrix[3][3] + elementMatrix[4][3] return elementX, elementY, elementZ end function getInFrontOf(x, y, angle, distance) distance = distance or 1 if x and not y then return x + distance * math.sin(math.rad(-angle)) elseif not x and y then return y + distance * math.cos(math.rad(-angle)) elseif x and y then return x + distance * math.sin(math.rad(-angle)), y + distance * math.cos(math.rad(-angle)) end end function getCameraRotation() local cx, cy, _, tx, ty = getCameraMatrix() return math.deg(math.atan2(tx - cx, ty - cy)) end Thanks the replies.
-
I have a big problem with this code. When i enter a vehicle then the camera is attaching, and the free cam is also working. But when i rotate the vehicles x position 180 degree then the camera is at the same position. I want to attach the camera to a fix point on the vehicle. So my problem is that its not attaching the camera to that point 100 %. its a really strange bug. I could not explain it correctly, maybe you can test it, and then you will see the bug. So i want to attach it like in the bone attach resource. local vvx, vvy, vvz = 0,0,0 function vehicle_cam(screenX, screenY, absoluteX, absoluteY, vx,vy,vz) local x,y,z = getElementPosition(getPedOccupiedVehicle(getLocalPlayer())) if ( vx and vy and vz ) then vvx, vvy, vvz = vx, vy, vz end setCameraMatrix ( x+4.7, y-0.66, z+3.2, vvx, vvy, vvz ); end addEventHandler("onClientRender", root, vehicle_cam) addEventHandler("onClientCursorMove", getRootElement(), vehicle_cam)
-
Hello Guys, I just want to write a camera system like in GTA 5. (The Camera is closer to the player, etc) So i can aim with any weapon, but not rotating the ped. Cannot look around, cannot look up, or down when aiming. Any Ideas? local camera = {} local currentCameraView = 1 local cameraView = {} cameraView[1] = 1.2 --SimpleControl cameraView[2] = 6.5 --InVehicle camera.dist = cameraView[currentCameraView] camera.speed = 4 camera.x = math.rad(60) camera.y = math.rad(60) camera.z = math.rad(15) camera.maxZ = math.rad(89) camera.minZ = math.rad(-45) addEventHandler("onClientPreRender", getRootElement(), function() x, y, z = getElementPosition(localPlayer) z = z + 0.2 local camDist = camera.dist local cosZ = math.cos(camera.z) camX = x + math.cos(camera.x)*camDist*cosZ camY = y + math.sin(camera.y)*camDist*cosZ camZ = z + math.sin(camera.z)*camDist setCameraMatrix(camX, camY, camZ + 0.2, x + 0.1, y + 0.1, z + 0.2) end) addEventHandler("onClientCursorMove", getRootElement(), function(curX, curY, absX, absY) local diffX = curX - 0.5 local diffY = curY - 0.5 local camX = camera.x - diffX*camera.speed local camY = camera.y - diffX*camera.speed local camZ = camera.z + (diffY*camera.speed)/math.pi if(camZ > camera.maxZ)then camZ = camera.maxZ end if(camZ < camera.minZ)then camZ = camera.minZ end camera.x = camX camera.y = camY camera.z = camZ end) function isItInVeh() isitin = isPedInVehicle(localPlayer) if isitin == true then currentCameraView = 2 else currentCameraView = 1 end camera.dist = cameraView[currentCameraView] end addEventHandler("onClientPreRender", getRootElement(), isItInVeh) bindKey("mouse_wheel_down", "down", function() cameraView[1] = cameraView[1] + 0.1 if(cameraView[1] >= 2.5)then cameraView[1] = 2.5 end camera.dist = cameraView[currentCameraView] end) bindKey("mouse_wheel_up", "down", function() cameraView[1] = cameraView[1] - 0.1 if(cameraView[1] <= 1.2)then cameraView[1] = 1.2 end camera.dist = cameraView[currentCameraView] end) bindKey("mouse_wheel_down", "down", function() cameraView[2] = cameraView[2] + 0.4 if(cameraView[2] >= 12.5)then cameraView[2] = 12.5 end camera.dist = cameraView[currentCameraView] end) bindKey("mouse_wheel_up", "down", function() cameraView[2] = cameraView[2] - 0.4 if(cameraView[2] <= 6)then cameraView[2] = 6 end camera.dist = cameraView[currentCameraView] end) addEventHandler("onClientRender", getRootElement(), function() if isCursorShowing() then camera.speed = 0 elseif isChatBoxInputActive() then camera.speed = 0 else camera.speed = 4 end end) -----------------------------The Aiming Magic bindKey("aim_weapon", "down", function() outputChatBox("Aiming") end) bindKey("aim_weapon", "up", function() outputChatBox("Not Aiming") end)