setting a body (not shape) as a sensor

its easy to set a body to be a sensor with:

Code:
var theShapeDef:b2PolygonDef = new b2PolygonDef();
//.. some other theShapeDef arguments go here...
theShapeDef.isSensor = true; // <<< SET TO SENSOR

var theBodyDef:b2BodyDef = new b2BodyDef();
theBodyDef.position.Set(X, Y);

var theBody:b2Body = world.CreateBody(theBodyDef);
theBody.CreateShape(theShapeDef);
theBody.SetMassFromShapes();


but what if you already have a body and you want to set it to be a sensor?

should I do something like?
Code:
theBody.SetAsSensor(true); // THIS FUNCTION DOES NOT EXIST

no such command exists.. or anything simlar to it...
If you are using version 2.1 then the function does indeed exist. Bodies are containers for fixtures, which in turn contain the shapes. b2Fixture has a function called SetSensor().
Damn, my version must be old then.. Problem is, I've already been using this version of Box2D since the beginning for the game I'm currently making and have written a lot of code for it already.. I heard the new version is coded slightly different. it would be a hassle to suddenly change the Box2D version I am using.

Thanks for the tip though.. could use it in another project..
Looks like i gotta figure out a different approach for this one...
I'm confused. Simply setting all shapes in a body to sensor is all you can do, but what more do you expect?
nah.. its cause i'm making a game that uses boxes as obstacles.. normally, the player can hit the obstacles (boxes) and bounce off.. but there are times when the player should be able to just "walk-past" the boxes (for example, if the player eats a special fruit).. the contactlistener should still be able to pick up this "collision" / "hit-test" but not let the player bounce-off (which is exactly what a sensor does)

now how do i set a body to become a sensor when its already been created?
in my version of box2d, there is no quick function..

sall good though, i figure when the "allowPlayerToWalkPastBoxes()" functions runs, i'll just record all the positions, dimensions, etc of the boxes (bodies) inside an array, call DestroyBody on all the bodies, and then re-build new bodies on the exact same place where the previous bodies were (only this time, they are sensors)... all that should happen in one function and it shouldn't be noticeable that the bodies have actually been "replaced"...

once the "disallowPlayerToWalkPastBoxes()" function runs, i'll just do the same as above, except this time the bodies won't be set as sensors...

oh and btw, those aren't really the name of the functions.. just wanted to get a bit descriptive hahaha

Original thread: https://box2d.org/forum/viewtopic.php?t=4919