SetCameraTarget: Difference between revisions
m (update neafeauters) |
m (→Example) |
||
Line 45: | Line 45: | ||
g_Players = getElementsByType("player") -- get a list of all players in the server | 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 | for i,aPlayer in ipairs(g_Players) do -- find out what index the local player has in the list | ||
if aPlayer == | if aPlayer == localPlayer then | ||
g_CurrentSpectated = i | g_CurrentSpectated = i | ||
break | break |
Revision as of 12:12, 18 August 2015
This function allows you to set a player's camera to follow other elements instead. Currently supported element type is:
Syntax
bool setCameraTarget ( player thePlayer [, player target = nil ] )
OOP Syntax Help! I don't understand this!
- Method: player:setCameraTarget(...)
- Variable: .cameraTarget
- Counterpart: getCameraTarget
Required Arguments
- thePlayer: The player whose camera you wish to modify.
Optional Arguments
- target: The player who you want the camera to follow. If none is specified, the camera will target the player.
Note: setCameraTarget will behave strangely if the target you want the camera to follow is inside a vehicle that has hydraulics (upgrade id: 1087) added server sided and if the target is not you.
bool setCameraTarget ( player target )
Required Arguments
- target: The player who you want the local camera to follow.
This syntax mantains the player targeted by the camera, but makes the camera look at the specified coordinates. It has no effect when the camera doesn't have a target.
bool setCameraTarget ( float targetX, float targetY, float targetZ )
Required Arguments
- targetX, targetY, targetZ: The target position that you want the local camera to look at.
Returns
Returns true if the function was successful, false otherwise.
Example
This is an example of how one could implement a spectator function. Using the left and right arrow keys you can view other players. Note that this code isn't complete as it doesn't take into account joining or quitting players.
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)
Issues
Issue ID | Description |
---|---|
#7594 | setCameraTarget on a player inside a vehicle with hydraulics bugs camera |
See Also
- fadeCamera
- getCameraInterior
- getCameraMatrix
- getCameraTarget
- setCameraInterior
- setCameraMatrix
- setCameraTarget