PhysicsCreateShape

From Multi Theft Auto: Wiki
Revision as of 21:30, 18 February 2020 by CrosRoad95 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Creates physics shape used for static or dynamic collision detection

Syntax

physics-shape physicsCreateShape(physics thePhysics, shape-type theShapeType, mixed)
         
physics-shape physicsCreateShape(physics thePhysics, "box", float size)
physics-shape physicsCreateShape(physics thePhysics, "box", float sizeX, sizeY, sizeZ)
physics-shape physicsCreateShape(physics thePhysics, "sphere", float radius)
physics-shape physicsCreateShape(physics thePhysics, "capsule", float radius, float height)
physics-shape physicsCreateShape(physics thePhysics, "cone", float radius, float height)
physics-shape physicsCreateShape(physics thePhysics, "cylinder", float radius, float height)
physics-shape physicsCreateShape(physics thePhysics, "heightfieldterrain", int sizeX, int sizeY [, table heightData ] )
physics-shape physicsCreateShape(physics thePhysics, "compound", int initialChildCapacity = 0)
physics-shape physicsCreateShape(physics thePhysics, "trianglemesh", vector3 vertexA, vector3 vertexB, vector3 vertexC, ...)
physics-shape physicsCreateShape(physics thePhysics, "convexhull", vector3 pointA, vector3 pointB, vector3, pointC, ...)
  • heightfieldterrain: minimum size is 3x3, and maximum 8192x8192. By default terrain is flat, you can pass default height after size, each float represents height of next vertex.
  • trianglemesh: each of three vectors creates single triangle, use n*3 vectors to create n triangles.
  • compound: can contain up to 8192 child shapes.
  • convexhull: require at least 3 points.

Required Arguments

  • thePhysics: physics world
  • theShapeType: shape, availiable types "box", "sphere", "capsule", "cone", "cylinder", "heightfieldterrain", "compound", "trianglemesh", "convexhull",

Returns

  • physics-shape to use in future functions

Example

local terrainData = {
  3,3,3,3,
  3,0,0,3,
  3,0,0,3,
  3,3,3,3,
}
local terrainShape = physicsCreateShape(physics, "heightfieldterrain", 4,4, terrainData)
local terrain = physicsCreateStaticCollision(terrainShape)
physicsSetProperties(terrain, "position", 0,0,5)
physicsSetProperties(terrain, "scale", 5,5,1) -- in terrain, sets mesh density, now mesh has size 20x20units, one vertex every 5 units

See Also