Difference between revisions of "B2.Contact:setFriction"

From GiderosMobile
(added example)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2012.09.6<br/>
+
'''Available since:''' Gideros 2012.09.6<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.Contact|b2.Contact]]<br/>
+
'''Class:''' [[b2.Contact]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Overrides the default friction mixture. You can call this in pre-solve event. This value persists until set or reset. <br />
+
Overrides the default friction fixture. You can call this in pre-solve event. This value persists until set or reset.
<br /></translate>
 
 
<source lang="lua">
 
<source lang="lua">
b2.Contact:setFriction(friction)
+
b2.Contact:setFriction(friction)
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
+
 
'''friction''': (number) <translate></translate> <br/>
+
=== Parameters ===
 +
'''friction''': (number) the new friction value<br/>
 +
 
 +
=== Example ===
 +
<source lang="lua">
 +
function LevelX:onPreSolveContact(e)
 +
local bodyA = e.fixtureA:getBody()
 +
local bodyB = e.fixtureB:getBody()
 +
local platform, playable
 +
if bodyA.name == G_PTPLATFORM then platform = bodyA playable = bodyB
 +
elseif bodyB.name == G_PTPLATFORM then platform = bodyB playable = bodyA
 +
end
 +
if not platform then return end
 +
e.contact:setFriction(0.4) -- here ;-)
 +
end
 +
</source>
 +
 
 +
{{B2.Contact}}

Revision as of 13:50, 4 September 2021

Available since: Gideros 2012.09.6
Class: b2.Contact

Description

Overrides the default friction fixture. You can call this in pre-solve event. This value persists until set or reset.

b2.Contact:setFriction(friction)

Parameters

friction: (number) the new friction value

Example

function LevelX:onPreSolveContact(e)
	local bodyA = e.fixtureA:getBody()
	local bodyB = e.fixtureB:getBody()
	local platform, playable
	if bodyA.name == G_PTPLATFORM then platform = bodyA playable = bodyB
	elseif bodyB.name == G_PTPLATFORM then platform = bodyB playable = bodyA
	end
	if not platform then return end
	e.contact:setFriction(0.4) -- here ;-)
end




LiquidFun