Jump to content

[HELP] Wheel Camera


Imposter

Recommended Posts

Hey guys, I am trying to make a camera that looks up at the back up the car near the left wheel. Can somebody please help me out?

  
function setCamera() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local rx, ry, rz = getElementRotation(getLocalPlayer()) 
    setCameraMatrix(x-3, y-3, z, x+1, y+1, z+1) 
end 
addEventHandler("onClientPreRender", root, setCamera) 
addEventHandler("onClientResourceStart", resourceRoot, setCamera) 
addCommandHandler("setcamera", setCamera) 
  
--[[function resetCamera() 
     
end 
addCommandHandler("resetcamera", resetCamera)--]] 
  

Link to comment
ur trying to make it near a vehicles wheel but ur getting position of a player? why not the position of the vehicle a player is in who triggered the command?

But that still doesn't explain how to set the rotation so that it is always in that view

  
function setCamera() 
    local theCar = getPedOccupiedVehicle(getLocalPlayer()) 
    local x, y, z = getElementPosition(theCar) 
    local rx, ry, rz = getElementRotation(theCar) 
    setCameraMatrix(x-3*rx, y-3*ry, z, x+1, y+1, z+1) 
end 
addEventHandler("onClientPreRender", root, setCamera) 
addEventHandler("onClientResourceStart", resourceRoot, setCamera) 
addCommandHandler("setcamera", setCamera) 
  

Link to comment

https://wiki.multitheftauto.com/wiki/GetElementMatrix

function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element )  -- Get the matrix 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                               -- Return the transformed point 
end 
  
function setCamera() 
    local theCar = getPedOccupiedVehicle(localPlayer) 
    if theCar then 
        local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -2, 0 ); -- camera position at the left read side of the car (2 units to the left and 2 units to the back) 
        local lx, ly, lz = getPositionFromElementOffset( theCar, 2, 2, 0 ); -- get the position where the camera will look (2 units to the left and 2 units to the front) 
        setCameraMatrix( cx, cy, cz, lx, ly, lz ); 
    end 
end 
addEventHandler("onClientPreRender", root, setCamera) 
addEventHandler("onClientResourceStart", resourceRoot, setCamera) 
addCommandHandler("setcamera", setCamera) 
  

Link to comment
https://wiki.multitheftauto.com/wiki/GetElementMatrix
function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element )  -- Get the matrix 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                               -- Return the transformed point 
end 
  
function setCamera() 
    local theCar = getPedOccupiedVehicle(localPlayer) 
    if theCar then 
        local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -2, 0 ); -- camera position at the left read side of the car (2 units to the left and 2 units to the back) 
        local lx, ly, lz = getPositionFromElementOffset( theCar, 2, 2, 0 ); -- get the position where the camera will look (2 units to the left and 2 units to the front) 
        setCameraMatrix( cx, cy, cz, lx, ly, lz ); 
    end 
end 
addEventHandler("onClientPreRender", root, setCamera) 
addEventHandler("onClientResourceStart", resourceRoot, setCamera) 
addCommandHandler("setcamera", setCamera) 
  

:o thank you, i didnt know how to do it, now i do, thanks so much 50p. :D

Link to comment
No problem. Play around with different values to suit your needs. I just used 2 as an example.

Mhm, I used

  
        local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -4, 0 );  
        local lx, ly, lz = getPositionFromElementOffset( theCar, 1, 3, 1 ); 
  

Link to comment

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...