Difference between revisions of "R3d.Body:setType"

From GiderosMobile
 
Line 8: Line 8:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Must be one of the following:
+
There are three types of bodies: static, kinematic and dynamic.
 +
 
 +
A '''static body''' has infinite mass, zero velocity but its position can be changed manually. Moreover, a
 +
static body does not collide with other static or kinematic bodies.
 +
 
 +
A '''kinematic body''' has infinite mass, its velocity can be changed manually and its position is computed by the physics engine. A kinematic body does not collide with other static or kinematic bodies.
 +
 
 +
A '''dynamic body''' has non-zero mass, non-zero velocity determined by forces and its position is determined by the physics engine. Moreover, a dynamic body can collide with other dynamic, static or kinematic bodies.
 +
 
 +
For instance, you can use a static body for the floor, a kinematic body for a moving platform and a dynamic body for a rock that could fall on the floor.
 +
 
 +
When you create a new body in the world, it is of dynamic type by default.
 +
 
 +
=== Parameters ===
 +
'''type''': (number) the new body type, must be one of the following:
 
*r3d.Body.STATIC_BODY '''0'''
 
*r3d.Body.STATIC_BODY '''0'''
 
*r3d.Body.KINEMATIC_BODY '''1'''
 
*r3d.Body.KINEMATIC_BODY '''1'''
 
*r3d.Body.DYNAMIC_BODY '''2'''
 
*r3d.Body.DYNAMIC_BODY '''2'''
 
=== Parameters ===
 
'''type''': (number) the body type<br/>
 
  
 
=== Example ===
 
=== Example ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
plane.body:setType(r3d.Body.STATIC_BODY)
 
plane.body:setType(r3d.Body.STATIC_BODY)
cube01.body:setType(r3d.Body.KINEMATIC_BODY )
+
cube01.body:setType(r3d.Body.KINEMATIC_BODY)
 
cube02.body:setType(2)
 
cube02.body:setType(2)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
{{R3d.Body}}
 
{{R3d.Body}}

Latest revision as of 10:54, 18 December 2025

Available since: Gideros 2019.10
Class: R3d.Body

Description

Sets the body type.

r3d.Body:setType(type)

There are three types of bodies: static, kinematic and dynamic.

A static body has infinite mass, zero velocity but its position can be changed manually. Moreover, a static body does not collide with other static or kinematic bodies.

A kinematic body has infinite mass, its velocity can be changed manually and its position is computed by the physics engine. A kinematic body does not collide with other static or kinematic bodies.

A dynamic body has non-zero mass, non-zero velocity determined by forces and its position is determined by the physics engine. Moreover, a dynamic body can collide with other dynamic, static or kinematic bodies.

For instance, you can use a static body for the floor, a kinematic body for a moving platform and a dynamic body for a rock that could fall on the floor.

When you create a new body in the world, it is of dynamic type by default.

Parameters

type: (number) the new body type, must be one of the following:

  • r3d.Body.STATIC_BODY 0
  • r3d.Body.KINEMATIC_BODY 1
  • r3d.Body.DYNAMIC_BODY 2

Example

plane.body:setType(r3d.Body.STATIC_BODY)
cube01.body:setType(r3d.Body.KINEMATIC_BODY)
cube02.body:setType(2)