SetElementCollisionsEnabled: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
(21 intermediate revisions by 14 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function can disable or enable an element's collisions. An element without collisions does not interact with the physical environment and remains static. | This function can disable or enable an element's collisions. An element without collisions does not interact with the physical environment and remains static. | ||
{{Note|Vehicles that are collisionless and have a driver will cause bugs.}} | |||
{{Note|Enabling a players collisions when they're inside a vehicle will cause bugs.}} | |||
{{Note|Disabling a peds collisions will cause some problems, such as it being unable to move or wrong rotation after creation.}} | |||
==Syntax== | ==Syntax== | ||
Line 7: | Line 11: | ||
bool setElementCollisionsEnabled ( element theElement, bool enabled ) | bool setElementCollisionsEnabled ( element theElement, bool enabled ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:setCollisionsEnabled|collisions|getElementCollisionsEnabled}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 16: | Line 21: | ||
==Example== | ==Example== | ||
This example | This example disables collisions for all vehicles within a certain radius of a player: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function disableVehicleCollisionsNearPlayer(thePlayer, maxDistance) | ||
local playerX, playerY, playerZ = getElementPosition( | local playerX, playerY, playerZ = getElementPosition(thePlayer) | ||
local vehicles = getElementsByType("vehicle") | local vehicles = getElementsByType("vehicle") | ||
for k,v in ipairs(vehicles) do | for k,v in ipairs(vehicles) do | ||
local vehicleX, vehicleY, vehicleZ = getElementPosition(v) | local vehicleX, vehicleY, vehicleZ = getElementPosition(v) | ||
-- get the distance between the player and the vehicle: | -- get the distance between the player and the vehicle: | ||
local distance = | local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) | ||
if (distance <= maxDistance) then | if (distance <= maxDistance) then | ||
-- | -- disable collisions for the vehicle | ||
setElementCollisionsEnabled(v, | setElementCollisionsEnabled(v, false) | ||
end | end | ||
end | end | ||
Line 34: | Line 39: | ||
==See Also== | ==See Also== | ||
{{ | {{Client element functions}} |
Latest revision as of 16:27, 20 January 2020
This function can disable or enable an element's collisions. An element without collisions does not interact with the physical environment and remains static.
Syntax
bool setElementCollisionsEnabled ( element theElement, bool enabled )
OOP Syntax Help! I don't understand this!
- Method: element:setCollisionsEnabled(...)
- Variable: .collisions
- Counterpart: getElementCollisionsEnabled
Required Arguments
- theElement: The element you wish to set the collisions of
- enabled: A boolean to indicate whether collisions are enabled (true) or disabled (false)
Returns
Returns true if the collisions were set succesfully, false otherwise.
Example
This example disables collisions for all vehicles within a certain radius of a player:
function disableVehicleCollisionsNearPlayer(thePlayer, maxDistance) local playerX, playerY, playerZ = getElementPosition(thePlayer) local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles) do local vehicleX, vehicleY, vehicleZ = getElementPosition(v) -- get the distance between the player and the vehicle: local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, playerX, playerY, playerZ) if (distance <= maxDistance) then -- disable collisions for the vehicle setElementCollisionsEnabled(v, false) end end end
See Also
- getElementBoneMatrix
- getElementBonePosition
- getElementBoneRotation
- getElementBoundingBox
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementLighting
- getElementRadius
- isElementCollidableWith
- isElementLocal
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementWaitingForGroundToLoad
- setElementBoneMatrix
- setElementBonePosition
- setElementBoneRotation
- setElementCollidableWith
- setElementStreamable
- updateElementRpHAnim
- Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement