Difference between revisions of "R3d.Fixture:setMaterial"
From GiderosMobile
(update to r3d v0.8) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
=== Description === | === Description === | ||
Sets the fixture material (bounciness, frictionCoefficient, rollingResistance). | Sets the fixture material (bounciness, frictionCoefficient, rollingResistance). | ||
− | < | + | <syntaxhighlight lang="lua"> |
r3d.Fixture:setMaterial(material) | r3d.Fixture:setMaterial(material) | ||
− | </ | + | </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 === | ||
Line 12: | Line 16: | ||
=== Example === | === Example === | ||
− | < | + | <syntaxhighlight lang="lua"> |
-- the body | -- the body | ||
view.body = xworld:createBody(view:getMatrix()) | view.body = xworld:createBody(view:getMatrix()) | ||
Line 19: | Line 23: | ||
-- materials default: bounciness=0.5, frictionCoefficient=0.3, rollingResistance=0 | -- materials default: bounciness=0.5, frictionCoefficient=0.3, rollingResistance=0 | ||
local mat = fixture:getMaterial() | local mat = fixture:getMaterial() | ||
− | mat.bounciness = 0.1 | + | mat.bounciness = 0.1 -- 0 = no bounciness, 1 = max bounciness |
− | mat.frictionCoefficient = 0.5 | + | mat.frictionCoefficient = 0.5 -- 0 = no friction |
− | mat.rollingResistance = 0.1 -- | + | --mat.rollingResistance = 0.1 -- DEPRECATED! |
fixture:setMaterial(mat) | fixture:setMaterial(mat) | ||
− | </ | + | </syntaxhighlight> |
{{R3d.Fixture}} | {{R3d.Fixture}} |
Latest revision as of 14:32, 13 July 2023
Available since: Gideros 2019.10
Class: R3d.Fixture
Description
Sets the fixture material (bounciness, frictionCoefficient, rollingResistance).
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
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 -- 0 = no bounciness, 1 = max bounciness
mat.frictionCoefficient = 0.5 -- 0 = no friction
--mat.rollingResistance = 0.1 -- DEPRECATED!
fixture:setMaterial(mat)