Jump to content

setCameraBehindPlayer


Glo

Recommended Posts

give some code to reproduce "not always working" - i was using this function many times in complicated scripts - and it was ALWAYS working..

For example, it doesn't work under a certain delay amount (sometimes 100ms, another time 1000ms - varies), and doesn't work without a timer at all.

Link to comment

author want to say that setCameraTarget(player) don't point camera from back to front of player skin. After setCameraTarget(player) camera may be pointed from side to side of player skin. Example = standard game mode "play". After spawn camera will be placed not to back but to left side from spawned player.

Link to comment

server side, not tested but should work

  
function getPositionRelatedToPed(thePed, val) 
    local xx, yy, zz = getElementPosition(thePed) 
    local rot = getPedRotation(thePed) 
    local lx = xx + math.sin (math.rad(-rot)) * val 
    local ly = yy + math.cos (math.rad(-rot)) * val 
    return lx,ly 
end 
  
function setCameraBehindPlayer(pl) 
  local xx,yy,zz = getElementPosition(pl) 
  local lx, ly = getPositionRelatedToPed(pl, -2) 
  setCameraMatrix(pl, lx, ly, zz+1, xx, yy, zz) 
  setCameraTarget(pl, pl) 
end 
  

Link to comment

But too much lines. Is easier to use (client-side):

addEventHandler ( "onClientPreRender", getRootElement(), 
function (  ) 
 setCameraTarget(  getLocalPlayer( )  ) 
end ) 

It does the same thing (just has problems trying to using mouse to up or down), in less lines.

Link to comment
server side, not tested but should work
  
function getPositionRelatedToPed(thePed, val) 
    local xx, yy, zz = getElementPosition(thePed) 
    local rot = getPedRotation(thePed) 
    local lx = xx + math.sin (math.rad(-rot)) * val 
    local ly = yy + math.cos (math.rad(-rot)) * val 
    return lx,ly 
end 
  
function setCameraBehindPlayer(pl) 
  local xx,yy,zz = getElementPosition(pl) 
  local lx, ly = getPositionRelatedToPed(pl, -2) 
  setCameraMatrix(pl, lx, ly, zz+1, xx, yy, zz) 
  setCameraTarget(pl, pl) 
end 
  

checked. Same things.. camera position is on the left side of player and target is on the right side of player. Look

mtascreen20101019113308.jpg

Link to comment
try this:
  
function setCameraBehindPlayer(pl) 
  local xx,yy,zz = getElementPosition(pl) 
  local lx, ly = getPositionRelatedToPed(pl, -2) 
  setCameraMatrix(pl, lx, ly, zz+1, xx, yy, zz) 
  setTimer(setCameraTarget, 50, 1, pl, pl) 
end 
  

for players with big ping may not work properly

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...