Thanks!
For future reference, this was the solution.
I created the character as one body with two shapes. One for the feet and one for the rest of the body. My character is very small, so two shapes are enough.
I make sure to set the userdata of the shape to a String so that it's easy to recognize.
In AS3 this is what I use to define the character
Code:
public function createActor():b2Body{
// define torso shape
var w:Number = 0.7;
var h:Number = 0.35;
var torsoBox:b2BoxDef = new b2BoxDef();
torsoBox.density = 1;
torsoBox.friction = 0.5;
torsoBox.extents.Set(w, h);
torsoBox.userData = "torso";
// define feet shape
var feetBox:b2BoxDef = new b2BoxDef();
feetBox.extents.Set(w*0.7, w*0.5);
feetBox.localPosition.Set( 0, h);
feetBox.density = 1.0;
feetBox.friction = 0.5;
feetBox.userData = "feet";
// define body
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set((Math.random() * 400 + 120) / m_physScale, (Math.random() * 150 + 50) / m_physScale);
bodyDef.preventRotation = true;
bodyDef.AddShape(torsoBox);
bodyDef.AddShape(feetBox);
// create body
var character:b2Body = m_world.CreateBody(bodyDef);
return character;
}
Now this is a function that you can use to determine if the body is resting.
Code:
public static function isResting(body:b2Body, shapeName:String):Boolean{
// loop the contactlist
for (var cn:b2ContactNode = body.m_contactList; cn != null; cn = cn.next){
// determine which shape is ours
var shape:b2Shape;
if(cn.contact.GetShape1().GetBody()==body){
shape = cn.contact.GetShape1();
}else{
shape = cn.contact.GetShape2();
}
// determine if it's the shape we are looking for
if(shape.m_userData == shapeName){return true;}
}
return false;
}
In my case I would use it like this to determine if my character is resting on it's feet:
Code:
trace("Is my character resting? " + isResting(character, "feet") );
Essentially I have a custom Actor class that has the isResting() function, but that's something you can implement yourself.