PhysicsAddChildShape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (CrosRoad95 moved page PhysicsAddShape to PhysicsAddChildShape)
No edit summary
 
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 24: Line 24:
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)
function createChainLink(x,y,z,rx,ry,rz)

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