setElementCollisionsEnabled | Multi Theft Auto: Wiki Skip to content

setElementCollisionsEnabled

Client-side
Server-side
Shared

Pair: getElementCollisionsEnabled

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


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

setElementCollisionsEnabled ( )

Code Examples

server

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

Element Functions