Entity/PhysicsInitMultiConvex

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(More accurate documentation)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=PhysicsInitMultiConvex
 
|Parent=Entity
 
 
|Description=An advanced version of {{ClassFunction|Entity|PhysicsInitConvex}} which initializes a physics object from multiple convex meshes.
 
|Description=An advanced version of {{ClassFunction|Entity|PhysicsInitConvex}} which initializes a physics object from multiple convex meshes.
  
Line 7: Line 5:
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes
 +
|Name=PhysicsInitMultiConvex
 +
|Parent=Entity
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 12: Line 12:
 
|name=vertices
 
|name=vertices
 
|desc=A table consisting of tables of {{Type|Vector}}s. Each sub-table defines a set of points to be used in the computation of one convex mesh.
 
|desc=A table consisting of tables of {{Type|Vector}}s. Each sub-table defines a set of points to be used in the computation of one convex mesh.
 +
}}
 +
{{Example
 +
|Description=Creates a "box" physics mesh for the entity.
 +
|Code=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
 
}}
 
}}

Revision as of 08:12, 17 July 2016

 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