Difference between revisions of "R3d.World:createBody"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 10: Line 10:
 
body = r3d.World:createBody(matrix)
 
body = r3d.World:createBody(matrix)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
When you create a new body in the world, it is of dynamic type by default '''[[R3d.Body.DYNAMIC BODY]]'''. You can change the type of the body using the RigidBody::setType() method '''[[R3d.Body:setType]]'''.
  
 
=== Parameters ===
 
=== Parameters ===

Latest revision as of 11:08, 16 December 2025

Available since: Gideros 2019.10
Class: R3d.World

Description

A rigid body represents an object that you want to simulate in the world. It has a mass, a position, an orientation and one or several collision shapes. The dynamics world will compute collisions between the bodies and will update its position and orientation accordingly at each time step. You can also create joints between the bodies in the world.

In order to create a rigid body, you need to specify its transform.

body = r3d.World:createBody(matrix)

When you create a new body in the world, it is of dynamic type by default R3d.Body.DYNAMIC BODY. You can change the type of the body using the RigidBody::setType() method R3d.Body:setType.

Parameters

matrix: (matrix) the initial position and orientation of the body in the world

Example

-- mesh
local mesh = D3.Mesh.new()
local meshview = Viewport.new()
meshview:setContent(mesh)
-- transform
matrix = meshview:getMatrix()
matrix:setPosition(posx, posy, posz)
matrix:setRotationX(rotx)
matrix:setRotationY(roty)
matrix:setRotationZ(rotz)
meshview:setMatrix(matrix)
-- body
meshview.body = world:createBody(meshview:getMatrix())