Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How are sensors used in Gideros? — Gideros Forum

How are sensors used in Gideros?

Tom2012Tom2012 Guru
edited December 2012 in General questions
In the box2D manual, there's this section:
 
    Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. This is done by using sensors. A sensor is a fixture that detects collision but does not produce a response.
 
    You can flag any fixture as being a sensor. Sensors may be static or dynamic. Remember that you may have multiple fixtures per body and you can have any mix of sensors and solid fixtures.
 
    Sensors do not generate contact points. There are two ways to get the state of a sensor:
 
        b2Contact::IsTouching
        b2ContactListener::BeginContact and EndContact
But I'm having trouble finding how to implement it in Gideros.

I can create a fixture on a body easily enough and set it as a sensor, but not sure how to do the begin contact part?

Thanks

Tom

Comments

  • Sorry, figured this out.

    I think you just create the fixture and use:

    fixture.name = "ground sensor"

    Then use something like...
    	local function onBeginContact(event)
     
    		-- you can get the fixtures and bodies in this contact like:
    		local fixtureA = event.fixtureA
    		local fixtureB = event.fixtureB
    		local bodyA = fixtureA:getBody()
    		local bodyB = fixtureB:getBody()
     
    if(fixtureB.name=="ground sensor") then
     -- character is on ground etc...
    end
    Does that sound right?

    (I was trying to use pre-solve which I'm guessing won't work as it's a sensor...)

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • zvardinzvardin Member
    Accepted Answer
    Yeah, you just check for collisions like you said as per usual. Setting it as a sensor just means that fixture won't cause default physic reactions (it hitting something will cause no force).

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.