SetCameraTarget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 76: | Line 76: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Q: Why it's in a timer? | |||
A: You have to put the second call in a timer, because the server will skip the second call if you won't delay it (he thinks that it's not necessary). | |||
==See Also== | ==See Also== | ||
{{Camera functions}} | {{Camera functions}} |
Revision as of 21:42, 6 August 2010
This function allows you to set a player's camera to follow other elements instead. Currently supported element type is:
Syntax
Click to collapse [-]
Serverbool setCameraTarget ( player thePlayer, [ element target ] )
Required Arguments
- thePlayer: The player whose camera you wish to modify.
Optional Arguments
- target: The element that you want the camera to follow. If none is specified, the camera will target the player.
Click to collapse [-]
Clientbool setCameraTarget ( element target )
Required Arguments
- target: The element that you want the local camera to follow.
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.
Click to collapse [-]
Client scriptg_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 == getLocalPlayer() 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)
By default setCameraTarget will look at the player front, but if you want it to look from the back then you have to call the setCameraTarget twice, like this:
Click to collapse [-]
Server script... setCameraTarget(source) setTimer(setCameraTarget, 100, 1, source) ...
Q: Why it's in a timer? A: You have to put the second call in a timer, because the server will skip the second call if you won't delay it (he thinks that it's not necessary).
See Also
- fadeCamera
- getCameraInterior
- getCameraMatrix
- getCameraTarget
- setCameraInterior
- setCameraMatrix
- setCameraTarget