I'm working on a platformer game and having problems finding the ground normal beneath the player's character. I have no problem testing whether my character is on the ground using this little function:
Code:
private function _onGround(sensor:BodyShape):Boolean {
var list:ContactList = contacts[sensor];
list.clean();
return (list.values.length > 0);
}
...but when I try to find the normal using the exact same
ContactList as the above function, there's never any information there. I've tried copying the code directly out of
parseInput() from
BoxMan.as. Although the manifold object receives a value, it's
normal property is always null. Here's my code as it stands...
Code:
public function groundNormal(sensor:BodyShape):Number {
var list:ContactList = contacts[sensor];
if(!list.isEmpty()) {
list.forEach(function(keys:Array, item:ContactEvent) {
var wm:b2WorldManifold = item.getWorldManifold();
if (wm.normal) return wm.normal.angle();
});
}
return 0;
}