Jump to content

setCameraBehindPlayer


Glo

Recommended Posts

Posted

setCameraBehindPlayer(player) - ability to set camera directly behind a player.

Can be done using setCameraTarget at the moment, but unfortunately that method does not always work and requires a timer.

Posted

Needs to be done like this to set the cam behind player:

  
setCameraTarget(player) 
setTimer(setCameraTarget, 1000, 1, player) 
  

and then still doesn't work all times. That's why a dedicated function would be better

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

Posted

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.

Posted

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 
  

Posted

Sorry this reply but, if you set the player's camera target as itself, it doesn't delete old camera matrices configurations?

Posted

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.

Posted
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

Posted

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 
  

Posted
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

  • Recently Browsing   0 members

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