setCameraTarget | Multi Theft Auto: Wiki Skip to content

setCameraTarget

Client-side
Server-side
Shared

Pair: getCameraTarget

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function allows you to set a player's camera to follow other elements instead. Currently supported element type is:

OOP Syntax Help! I don't understand this!

  • Method: player:setCameraTarget(...)
  • Variable: .cameraTarget

Syntax

bool setCameraTarget ( float targetX, float targetY, float targetZ )
Required Arguments
  • targetX: MISSING_PARAM_DESC
  • targetY: MISSING_PARAM_DESC
  • targetZ: MISSING_PARAM_DESC

Returns

  • bool: value

Returns true if the function was successful, false otherwise.

Code Examples

client
g_Players = getElementsByType("player") -- get a list of all players in the server
for i,aPlayer in ipairs(g_Players) do -- find out what index the local player has in the list
if aPlayer == localPlayer then
g_CurrentSpectated = i
break
end
end
function spectatePrevious() -- decrement the spectate index and spectate the corresponding player
if g_CurrentSpectated == 1 then
g_CurrentSpectated = #g_Players
else
g_CurrentSpectated = g_CurrentSpectated - 1
end
setCameraTarget(g_Players[g_CurrentSpectated])
end
function spectateNext() -- increment the spectate index and spectate the corresponding player
if g_CurrentSpectated == #g_Players then
g_CurrentSpectated = 1
else
g_CurrentSpectated = g_CurrentSpectated + 1
end
setCameraTarget(g_Players[g_CurrentSpectated])
end
-- Bind above functions to arrow keys
bindKey("arrow_l", "down", spectatePrevious)
bindKey("arrow_r", "down", spectateNext)