Jump to content

Recommended Posts

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)

 

```

Link to comment
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

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)
      local _,_, pRotZ = getElementRotation(localPlayer)
      local fx, fy, fz = getPositionFromElementOffset(camera, 10,0,0)

      setCameraMatrix(x2,y2,z2, fx,fy,fz)
      
end

end

addCommandHandler("live",didanlive)


function camset()

  setCameraTarget(localPlayer)
  removeEventHandler ( "onClientRender", root, didanlive )


end


addCommandHandler("ended",camset)

can you try this

Link to comment
1 hour ago, Burak5312 said:
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

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)
      local _,_, pRotZ = getElementRotation(localPlayer)
      local fx, fy, fz = getPositionFromElementOffset(camera, 10,0,0)

      setCameraMatrix(x2,y2,z2, fx,fy,fz)
      
end

end

addCommandHandler("live",didanlive)


function camset()

  setCameraTarget(localPlayer)
  removeEventHandler ( "onClientRender", root, didanlive )


end


addCommandHandler("ended",camset)

can you try this

Still having a problem
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...