SetElementCollisionsEnabled: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
{{Client function}}  
{{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.<br>
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>
Line 5: Line 5:


{{New feature|3.0110|1.1|
{{New feature|3.0110|1.1|
Server and clientside in 1.1
Available server-side. Only available client-side for 1.0.4 and lower.
}}
}}


Line 22: Line 22:
==Example==  
==Example==  
This example disables collisions for all vehicles within a certain radius of a player:
This example disables 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 disableVehicleCollisionsNearPlayer(thePlayer, maxDistance)
function disableVehicleCollisionsNearPlayer(thePlayer, maxDistance)
Line 38: Line 37:
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Client element functions}}
{{Client element functions}}

Revision as of 10:33, 8 November 2010

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.

Available server-side. Only available client-side for 1.0.4 and lower.

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 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