PhysicsAddChildShape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} Adds child shape to already existing, compound shape. Limit: 8196 child shapes. ==Syntax== <syntaxhighlight lang="lua"> boolean physicsAddShap...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
boolean physicsAddShape(physics-shape compoundShape, physics-shape childShape [, float offsetX, float offsetY, float offsetZ [, float offsetRotationX, float  offsetRotationY, float offsetRotationZ] ] )
boolean physicsAddChildShape(physics-shape compoundShape, physics-shape childShape [, float offsetX, float offsetY, float offsetZ [, float offsetRotationX, float  offsetRotationY, float offsetRotationZ] ] )
</syntaxhighlight>
</syntaxhighlight>


Line 21: Line 21:
Creates something that reminds chain
Creates something that reminds chain
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local function createChainLink(x,y,z,rx,ry,rz)
 
  local compound = physicsCreateShape(physics, "compound")
local compound = physicsCreateShape(physics, "compound")
  local capsule = physicsCreateShape(physics, "capsule", 0.2,1.5)
local capsule = physicsCreateShape(physics, "capsule", 0.2,1.5)
  physicsAddShape(compound, capsule)
physicsAddChildShape(compound, capsule)
  physicsAddShape(compound, capsule, 0,1,0.5, 45,0,0)
physicsAddChildShape(compound, capsule, 0,1,0.5, 45,0,0)
  physicsAddShape(compound, capsule, 0,1,0.5, 45,0,0)
physicsAddChildShape(compound, capsule, 0,1,0.5, 45,0,0)
  physicsAddShape(compound, capsule, 0,-1,0.5, -45,0,0)
physicsAddChildShape(compound, capsule, 0,-1,0.5, -45,0,0)
  physicsAddShape(compound, capsule, 0,-0.8,1.5, 120,0,0)
physicsAddChildShape(compound, capsule, 0,-0.8,1.5, 120,0,0)
  physicsAddShape(compound, capsule, 0,0.8,1.5, -120,0,0)
physicsAddChildShape(compound, capsule, 0,0.8,1.5, -120,0,0)
 
function createChainLink(x,y,z,rx,ry,rz)
   local link = physicsCreateRigidBody(physics,compound)
   local link = physicsCreateRigidBody(physics,compound)
   physicsSetProperties(link, "position", x,y,z)
   physicsSetProperties(link, "position", x,y,z)
Line 35: Line 37:
end
end


local function testChain()
function createChain()
   for i=1,2 do
   for i=1,2 do
     createChainLink(0,0,5 + i,0,0,0)
     createChainLink(0,0,5 + i,0,0,0)
Line 41: Line 43:
   end
   end
end
end
createChain()
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 14:37, 12 February 2020

Adds child shape to already existing, compound shape. Limit: 8196 child shapes.

Syntax

boolean physicsAddChildShape(physics-shape compoundShape, physics-shape childShape [, float offsetX, float offsetY, float offsetZ [, float offsetRotationX, float  offsetRotationY, float offsetRotationZ] ] )

Required Arguments

  • compoundShape: Must be compound shape
  • childShape: Can not be compound shape
  • offsetXYZ: Offset position of center
  • rotationXYZ: Offset rotationof center

Returns

True, if shape got added. False otherwise.

Example

Creates something that reminds chain


local compound = physicsCreateShape(physics, "compound")
local capsule = physicsCreateShape(physics, "capsule", 0.2,1.5)
physicsAddChildShape(compound, capsule)
physicsAddChildShape(compound, capsule, 0,1,0.5, 45,0,0)
physicsAddChildShape(compound, capsule, 0,1,0.5, 45,0,0)
physicsAddChildShape(compound, capsule, 0,-1,0.5, -45,0,0)
physicsAddChildShape(compound, capsule, 0,-0.8,1.5, 120,0,0)
physicsAddChildShape(compound, capsule, 0,0.8,1.5, -120,0,0)

function createChainLink(x,y,z,rx,ry,rz)
  local link = physicsCreateRigidBody(physics,compound)
  physicsSetProperties(link, "position", x,y,z)
  physicsSetProperties(link, "rotation", rx,ry,rz)
end

function createChain()
  for i=1,2 do
    createChainLink(0,0,5 + i,0,0,0)
    createChainLink(0,0,6 + i,0,0,90)
  end
end
createChain()

See Also