Difference between revisions of "B2.Fixture:setFilterData"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.Fixture|b2.Fixture]]<br/>
+
'''Class:''' [[b2.Fixture]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Sets the contact filtering data. This will not update contacts until the next time step<br />
+
Sets the contact filtering data. This will not update contacts until the next time step when either parent body is active and awake. The filter data definition is given as an ordinary table. The fields of the filter data table are:
when either parent body is active and awake. The filter data definition is given<br />
+
*''categoryBits'': (number) the collision category bits. Normally you would just set one bit
as a ordinary table. The fields of the filter data table are:<br />
+
*''maskBits'': (number) the collision mask bits. This states the categories that this shape would accept for collision
<br />
+
*''groupIndex'': (number) collision groups allow a certain group of objects to never collide (negative) or always collide (positive). Zero means no collision group. Non-zero group filtering always wins against the mask bits
<ul><br />
+
<syntaxhighlight lang="lua">
<li>`categoryBits`: (number) The collision category bits. Normally you would just set one bit.</li><br />
+
b2.Fixture:setFilterData(filterData)
<li>`maskBits`: (number) The collision mask bits. This states the categories that this shape would accept for collision.</li><br />
+
</syntaxhighlight>
<li>`groupIndex`: (number) Collision groups allow a certain group of objects to never collide (negative) or always collide (positive). Zero means no collision group. Non-zero group filtering always wins against the mask bits.</li><br />
+
 
</ul><br />
+
=== Parameters ===
<br /></translate>
+
'''filterData''': (table) the table containing the ''categoryBits'', the ''maskBits'' and the ''groupIndex''<br/>
<source lang="lua">
+
 
b2.Fixture:setFilterData(filterData)
+
=== Example ===
</source>
+
'''Example of fixtures collision filtering'''
=== <translate>Parameters</translate> ===
+
<syntaxhighlight lang="lua">
'''filterData''': (table) <translate></translate> <br/>
+
local BALL_MASK = 1
=== <translate>Examples</translate> ===
 
'''Example of fixtures collision filtering'''<br/>
 
<source lang="lua">local BALL_MASK = 1
 
 
local CRATE_MASK = 2
 
local CRATE_MASK = 2
 
local WALL_MASK = 4
 
local WALL_MASK = 4
Line 52: Line 49:
 
friction = 1, restitution = 0.3}
 
friction = 1, restitution = 0.3}
 
-- walls will collide with both balls and crates
 
-- walls will collide with both balls and crates
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})</source>
+
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})
 +
</syntaxhighlight>
 +
 
 +
{{B2.Fixture}}

Latest revision as of 16:50, 12 July 2023

Available since: Gideros 2011.6
Class: b2.Fixture

Description

Sets the contact filtering data. This will not update contacts until the next time step when either parent body is active and awake. The filter data definition is given as an ordinary table. The fields of the filter data table are:

  • categoryBits: (number) the collision category bits. Normally you would just set one bit
  • maskBits: (number) the collision mask bits. This states the categories that this shape would accept for collision
  • groupIndex: (number) collision groups allow a certain group of objects to never collide (negative) or always collide (positive). Zero means no collision group. Non-zero group filtering always wins against the mask bits
b2.Fixture:setFilterData(filterData)

Parameters

filterData: (table) the table containing the categoryBits, the maskBits and the groupIndex

Example

Example of fixtures collision filtering

local BALL_MASK = 1
local CRATE_MASK = 2
local WALL_MASK = 4
 
-- ball
local body = world:createBody{type = b2.DYNAMIC_BODY}
local circle = b2.CircleShape.new(0, 0, radius)
local fixture = body:createFixture{shape = circle, density = 1.0, 
friction = 0.1, restitution = 0.2}
-- ball will collide with other ball and wall
fixture:setFilterData({categoryBits = BALL_MASK, maskBits = BALL_MASK + WALL_MASK, groupIndex = 0})

local body = world:createBody{type = b2.DYNAMIC_BODY}
local poly = b2.PolygonShape.new()
poly:setAsBox(width, height)
local fixture = body:createFixture{shape = poly, density = 1.0, 
friction = 0.1, restitution = 0.2}
-- crate will collide with other crate and wall
fixture:setFilterData({categoryBits = CRATE_MASK, maskBits = CRATE_MASK + WALL_MASK, groupIndex = 0})

local body = world:createBody{type = b2.STATIC_BODY}
local chain = b2.ChainShape.new()
chain:createLoop(
	0,0,
	application:getContentWidth(), 0,
	application:getContentWidth(), application:getContentHeight(),
	0, application:getContentHeight()
)
local fixture = body:createFixture{shape = chain, density = 1.0, 
friction = 1, restitution = 0.3}
-- walls will collide with both balls and crates
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})




LiquidFun