Entity/PhysicsInitMultiConvex

From Garry's Mod
Revision as of 08:12, 17 July 2016 by Robotboy655 (Talk | contribs)
Jump to: navigation, search
 Entity:PhysicsInitMultiConvex( )

Contents

Description

An advanced version of Entity:PhysicsInitConvex which initializes a physics object from multiple convex meshes.

This should be used for physics objects with a custom shape which cannot be represented by a single convex mesh.

Arguments

table vertices

A table consisting of tables of Vectors. Each sub-table defines a set of points to be used in the computation of one convex mesh.

Examples

Example

Creates a "box" physics mesh for the entity.

function ENT:Initialize()
	if ( CLIENT ) then return end -- We only want to run this code serverside

	local x0 = -20 -- Define the min corner of the box
	local y0 = -10
	local z0 = -5

	local x1 = 20 -- Define the max corner of the box
	local y1 = 10
	local z1 = 5

	self:PhysicsInitMultiConvex( { {
		Vector( x1, y1, z1 ),
		Vector( x1, y0, z1 ),
		Vector( x0, y0, z1 ),
		Vector( x0, y1, z1 ),
		Vector( x1, y1, z1 ),
		Vector( x0, y0, z1 ),

		Vector( x0, y0, z0 ),
		Vector( x1, y0, z0 ),
		Vector( x0, y1, z0 ),
		Vector( x1, y0, z0 ),
		Vector( x1, y1, z0 ),
		Vector( x0, y1, z0 ),

		Vector( x1, y1, z1 ),
		Vector( x1, y1, z0 ),
		Vector( x1, y0, z0 ),
		Vector( x1, y0, z1 ),
		Vector( x1, y1, z1 ),
		Vector( x1, y0, z0 ),

		Vector( x0, y0, z0 ),
		Vector( x0, y1, z0 ),
		Vector( x0, y0, z1 ),
		Vector( x0, y1, z0 ),
		Vector( x0, y1, z1 ),
		Vector( x0, y0, z1 ),

		Vector( x1, y0, z1 ),
		Vector( x1, y0, z0 ),
		Vector( x0, y0, z0 ),
		Vector( x0, y0, z1 ),
		Vector( x1, y0, z1 ),
		Vector( x0, y0, z0 ),

		Vector( x0, y1, z0 ),
		Vector( x1, y1, z0 ),
		Vector( x0, y1, z1 ),
		Vector( x1, y1, z0 ),
		Vector( x1, y1, z1 ),
		Vector( x0, y1, z1 )
	} } )

	-- Set up solidity and movetype
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )

	-- Enable custom collisions on the entity
	self:EnableCustomCollisions( true )
end


Personal tools
Navigation