PhysicsAddChildShape

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

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