R3d.Fixture:setMaterial: Difference between revisions

From GiderosMobile
Created page with "'''Available since:''' Gideros 2019.10<br/> '''Class:''' R3d.Body<br/> === Description === Sets the body material (bounciness, frictionCoefficient, rollingResistance). <s..."
 
No edit summary
 
(5 intermediate revisions by 2 users not shown)
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'', ''massDensity'').
<source lang="lua">
<syntaxhighlight lang="lua">
r3d.Body:setMaterial(material)
r3d.Fixture:setMaterial(material)
</source>
</syntaxhighlight>
 
'''warnings''': not setting material.bounciness between (0, 1) will crash your app!
'''warnings''': setting material.frictionCoefficient a negative value will crash your app!
'''warnings''': material.rollingResistance is deprecated use '''[[R3d.Body:setAngularDamping]]''' instead


=== Parameters ===
=== Parameters ===
'''material''': (table) the body material table<br/>
'''material''': (table) the fixture material table:<br/>
*material.'''bounciness'''
*material.'''frictionCoefficient'''
*material.'''massDensity'''


=== Example ===
=== Example ===
<source lang="lua">
<syntaxhighlight lang="lua">
local mat = shipvp.body:getMaterial()
-- the body
mat.bounciness = 0.1 -- default = 0.5
view.body = world: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, massDensity=1 Kg
</source>
local mat = fixture:getMaterial()
mat.bounciness = 0.1 -- 0 = no bounciness, 1 = max bounciness
mat.frictionCoefficient = 0.5 -- 0 = no friction
--mat.rollingResistance = 0.1 -- DEPRECATED!
mat.massDensity = 5 -- in Kg
 
fixture:setMaterial(mat)
</syntaxhighlight>


{{R3d.Body}}
{{R3d.Fixture}}

Latest revision as of 01:08, 19 December 2025

Available since: Gideros 2019.10
Class: R3d.Fixture

Description

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

r3d.Fixture:setMaterial(material)
warnings: not setting material.bounciness between (0, 1) will crash your app!
warnings: setting material.frictionCoefficient a negative value will crash your app!
warnings: material.rollingResistance is deprecated use R3d.Body:setAngularDamping instead

Parameters

material: (table) the fixture material table:

  • material.bounciness
  • material.frictionCoefficient
  • material.massDensity

Example

-- the body
view.body = world: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, massDensity=1 Kg
local mat = fixture:getMaterial()
mat.bounciness = 0.1 -- 0 = no bounciness, 1 = max bounciness
mat.frictionCoefficient = 0.5 -- 0 = no friction
--mat.rollingResistance = 0.1 -- DEPRECATED!
mat.massDensity = 5 -- in Kg

fixture:setMaterial(mat)