setElementRotation
Client-side
Server-side
Shared
Pair: getElementRotation
Sets the rotation of elements according to the world.
Note
- This function does not work on colshape and dummy-elements created by createElement.
- The default rotation order for peds/players is
Z-Y-X(clientside) and-Z-Y-X(serverside) but those rotation orders (set using "default" on peds) can not be used manually on other element types since they only exist due to historical and backward compatibility reasons. Specifying a rotation order other thandefaultallows the same angles to later be uniformly used on several elements without having to consider their type.
Tip
New scripts should set conformPedRotation to true when using this function on peds. This will prevent quirky old behaviour.
OOP Syntax Help! I don't understand this!
- Method:element:setRotation(...)
- Variable: .rotation
Syntax
bool setElementRotation ( element theElement, float rotX, float rotY, float rotZ, [ string rotOrder = "default", bool conformPedRotation = false ] )Required Arguments
- theElement: The element whose rotation will be set.
- rotX: The element's rotation around the x axis in degrees.
- rotY: The element's rotation around the y axis in degrees.
- rotZ: The element's rotation around the z axis in degrees.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- rotOrder (default: "default"): A string representing the rotation order desired when interpreting the provided euler angles.
- default: Default MTA behavior prior to 1.1, where rotation order depends on element type.
- ZXY: Rotation about the Z axis (up), then about the resulting X axis (right) and finally about the resulting Y axis (front). This is the default rotation order for objects.
- ZYX: Rotation about the Z axis (up), then about the resulting Y axis (front), and finally about the resulting X axis (right). This is the default rotation order for vehicles.
- conformPedRotation (default: false): Relevant only for peds and will be ignored for other element types. A bool which should be set to true to ensure the ped rotation is correctly set in all circumstances. Failing to set this argument may result in the ped rotation being inverted whilst it is in the air and other inconsistencies. The default value of false is for backward compatibility with scripts which may depend upon the incorrect behaviour.
Returns
- bool: result
Returns true if the element rotation was successfully set and false otherwise.
Code Examples
client
How to correctly set the rotation for a ped.
function pedRotate() local rotX, rotY, rotZ = getElementRotation(localPlayer) -- get the local players's rotation setElementRotation(localPlayer, 0, 0, rotZ + 10, "default", true) -- turn the player 10 degrees clockwiseendaddCommandHandler("turn", pedRotate)Changelog
Added conformPedRotation argument.
See Also
Element Functions
- addElementDataSubscriber
- attachElements
- clearElementVisibleTo
- cloneElement
- createElement
- destroyElement
- detachElements
- getAllElementDataUpdated
- getAttachedElements
- getElementAlpha
- getElementAngularVelocity
- getElementAttachedOffsets
- getElementAttachedTo
- getElementBonePosition
- getElementBoneQuaternionNew
- getElementBoneRotation
- getElementBoundingBox
- getElementByID
- getElementByIndex
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getElementDimension
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementHealth
- getElementID
- getElementInterior
- getElementLighting
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRadius
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementSyncer
- getElementType
- getElementVelocity
- getElementZoneName
- getLowLODElement
- getRootElement
- hasElementData
- hasElementDataSubscriber
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementCollidableWith
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLocal
- isElementLowLOD
- isElementOnFireNew
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementVisibleTo
- isElementWaitingForGroundToLoad
- isElementWithinColShape
- isElementWithinMarker
- removeElementData
- removeElementDataSubscriber
- setElementAlpha
- setElementAngularVelocity
- setElementAttachedOffsets
- setElementBonePosition
- setElementBoneQuaternionNew
- setElementBoneRotation
- setElementCallPropagationEnabled
- setElementCollidableWith
- setElementCollisionsEnabled
- setElementDataUpdated
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementLightingNew
- setElementMatrix
- setElementModel
- setElementOnFireNew
- setElementParent
- setElementPosition
- setElementRotation
- setElementStreamable
- setElementSyncer
- setElementVelocity
- setElementVisibleTo
- setLowLODElement
- updateElementRpHAnim
Element Events
- onClientElementColShapeHit
- onClientElementColShapeLeave
- onClientElementDataChange
- onClientElementDestroy
- onClientElementDimensionChange
- onClientElementInteriorChange
- onClientElementModelChange
- onClientElementStreamIn
- onClientElementStreamOut
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync