SetElementCollisionsEnabled: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Client function}} | {{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.<br> | ||
'''Note:''' This function has unwanted effects on vehicles with drivers at the moment. | '''Note:''' This function has unwanted effects on vehicles with drivers at the moment. | ||
Line 18: | Line 18: | ||
==Example== | ==Example== | ||
This example enables collisions for all vehicles within a certain radius of a player: | This example enables collisions for all vehicles within a certain radius of a player: | ||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function enableVehicleCollisionsNearPlayer(thePlayer, maxDistance) | function enableVehicleCollisionsNearPlayer(thePlayer, maxDistance) | ||
Line 33: | Line 34: | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions}} |
Revision as of 13:05, 22 February 2009
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: This function has unwanted effects on vehicles with drivers at the moment.
Syntax
bool setElementCollisionsEnabled ( element theElement, bool enabled )
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 enables collisions for all vehicles within a certain radius of a player:
Click to collapse [-]
Clientfunction enableVehicleCollisionsNearPlayer(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 = math.sqrt((vehicleX - playerX)^2 + (vehicleY - playerY)^2 + (vehicleZ - playerZ)^2) if (distance <= maxDistance) then -- enable collisions for the vehicle setElementCollisionsEnabled(v, true) end end end
See Also
- 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