Difference between revisions of "R3d.Fixture:setMaterial"

From GiderosMobile
m (MoKaLux moved page R3d.Body:setMaterial to R3d.Fixture:setMaterial: update to r3d v0.8)
(update to r3d v0.8)
Line 1: Line 1:
 
'''Available since:''' Gideros 2019.10<br/>
 
'''Available since:''' Gideros 2019.10<br/>
'''Class:''' [[R3d.Body]]<br/>
+
'''Class:''' [[R3d.Fixture]]<br/>
  
 
=== Description ===
 
=== Description ===
Sets the body material (bounciness, frictionCoefficient, rollingResistance).
+
Sets the fixture material (bounciness, frictionCoefficient, rollingResistance).
 
<source lang="lua">
 
<source lang="lua">
r3d.Body:setMaterial(material)
+
r3d.Fixture:setMaterial(material)
 
</source>
 
</source>
  
 
=== Parameters ===
 
=== Parameters ===
'''material''': (table) the body material table<br/>
+
'''material''': (table) the fixture material table<br/>
  
 
=== Example ===
 
=== Example ===
 
<source lang="lua">
 
<source lang="lua">
local mat = shipvp.body:getMaterial()
+
-- the body
mat.bounciness = 0.1 -- default = 0.5
+
view.body = xworld:createBody(view:getMatrix())
mat.frictionCoefficient = 0.5 -- default = 0.3
+
local shape = r3d.SphereShape.new(params.sizex) -- radius
mat.rollingResistance = 1 -- default = 0 no rolling resistance
+
local fixture = view.body:createFixture(shape, nil, params.mass)
shipvp.body:setMaterial(mat)
+
-- materials default: bounciness=0.5, frictionCoefficient=0.3, rollingResistance=0
 +
local mat = fixture:getMaterial()
 +
mat.bounciness = 0.1
 +
mat.frictionCoefficient = 0.5
 +
mat.rollingResistance = 0.1 -- 0 = no resistance, 1 = max resistance
 +
fixture:setMaterial(mat)
 
</source>
 
</source>
  
{{R3d.Body}}
+
{{R3d.Fixture}}

Revision as of 21:51, 17 December 2020

Available since: Gideros 2019.10
Class: R3d.Fixture

Description

Sets the fixture material (bounciness, frictionCoefficient, rollingResistance).

r3d.Fixture:setMaterial(material)

Parameters

material: (table) the fixture material table

Example

-- the body
view.body = xworld:createBody(view:getMatrix())
local shape = r3d.SphereShape.new(params.sizex) -- radius
local fixture = view.body:createFixture(shape, nil, params.mass)
-- materials default: bounciness=0.5, frictionCoefficient=0.3, rollingResistance=0
local mat = fixture:getMaterial()
mat.bounciness = 0.1
mat.frictionCoefficient = 0.5
mat.rollingResistance = 0.1 -- 0 = no resistance, 1 = max resistance
fixture:setMaterial(mat)