SetPedCameraRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: {{Client function}} __NOTOC__ This function sets the camera rotation of a ped. ==Syntax== <syntaxhighlight lang="lua"> bool setPedCameraRotation ( ped ped, float rx, float ry, float rz ) </syntaxhighlight> ===R...)
 
mNo edit summary
 
(18 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
This function sets the camera rotation of a ped.
{{Note|[[getPedCameraRotation]] may not return the value set by this function. Please refer to [[getPedCameraRotation]] for details.}}
This function sets the camera rotation of a ped, e.g. where its camera will look at. Don't confuse this with [[getCameraMatrix]], because that function is designed for fixed (scripted) camera moves.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setPedCameraRotation ( ped ped, float rx, float ry, float rz )
bool setPedCameraRotation ( ped thePed, float cameraRotation )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[ped]]:setCameraRotation|cameraRotation|getPedCameraRotation}}


===Required Arguments===  
===Required Arguments===  
*'''ped:''' the PED element whose state is to be changed
*'''thePed:''' The [[ped]] whose camera rotation is to be changed.
*'''rx:''' the new rotation x
*'''cameraRotation:''' The new direction that the ped will walk if you set their forwards control state. If the ped is the local player, it will also change where his camera is looking at if it isn't fixed (i.e. camera target is the local player).
*'''ry:''' the new rotation y
*'''rz:''' the new rotation z


===Returns===
===Returns===
Returns ''true'' if the camera rotation could be changed, ''false'' otherwise.
Returns ''true'' if the camera rotation was changed, ''false'' otherwise.


==Example==  
==Example==


<syntaxhighlight lang="lua">--Write an example</syntaxhighlight>
The next code snippet adds a command called /rotatecam, which rotates the camera of the player who uses it.
<syntaxhighlight lang="lua">
function rotateLocalPlayerCamera()
    --setPedCameraRotation(localPlayer, getPedCameraRotation(localPlayer) + 45) -- This would work if getPedCameraRotation returned non-transformed angles
    setPedCameraRotation(localPlayer, -(getPedCameraRotation(localPlayer) + 45)) -- Tranform the angle returned and then add 45º to it
    outputChatBox("Your camera was rotated 45 degrees counter clockwise.", 0, 255, 0)
end
addCommandHandler("rotatecam", rotateLocalPlayerCamera)
</syntaxhighlight>


==See Also==
==See Also==
{{Ped functions}}
{{Client ped functions}}

Latest revision as of 18:42, 12 February 2021

[[{{{image}}}|link=|]] Note: getPedCameraRotation may not return the value set by this function. Please refer to getPedCameraRotation for details.

This function sets the camera rotation of a ped, e.g. where its camera will look at. Don't confuse this with getCameraMatrix, because that function is designed for fixed (scripted) camera moves.

Syntax

bool setPedCameraRotation ( ped thePed, float cameraRotation )

OOP Syntax Help! I don't understand this!

Method: ped:setCameraRotation(...)
Variable: .cameraRotation
Counterpart: getPedCameraRotation


Required Arguments

  • thePed: The ped whose camera rotation is to be changed.
  • cameraRotation: The new direction that the ped will walk if you set their forwards control state. If the ped is the local player, it will also change where his camera is looking at if it isn't fixed (i.e. camera target is the local player).

Returns

Returns true if the camera rotation was changed, false otherwise.

Example

The next code snippet adds a command called /rotatecam, which rotates the camera of the player who uses it.

function rotateLocalPlayerCamera()
    --setPedCameraRotation(localPlayer, getPedCameraRotation(localPlayer) + 45) -- This would work if getPedCameraRotation returned non-transformed angles
    setPedCameraRotation(localPlayer, -(getPedCameraRotation(localPlayer) + 45)) -- Tranform the angle returned and then add 45º to it
    outputChatBox("Your camera was rotated 45 degrees counter clockwise.", 0, 255, 0)
end
addCommandHandler("rotatecam", rotateLocalPlayerCamera)

See Also