SetElementCollisionsEnabled

From Multi Theft Auto: Wiki
Revision as of 01:03, 1 June 2007 by Erorr404 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 ) 

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:

function enableVehicleCollisionsNearPlayer(player, maxDistance)
	local playerX, playerY, playerZ = getElementPosition(player)
	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