I finally decided to try to come to grips with a sensor. After a day of scratching my head I think I've narrowed down my problem:
First I go creating my objects, this is in my main object creation:
I've confirmed my geometry is correct and debugdraw shows the GroundSensor poking into the ground at various times. However, in contactlistener:
No matter what happens in the simulation, this block of code only ever traces "No Userdata". I also repeat for Shape2 with similar results. I'm also getting this in the overriden "Persist" and "Remove" functions. 🙁
What's funny is I have this working perfectly for non-sensor objects. *sighs*
Can anyone give me a pointer as to where I'm going wrong?
First I go creating my objects, this is in my main object creation:
Code:
shapeDef.isSensor = true;
shapeDef.userData = "GroundSensor";
var theshape = body.CreateShape(shapeDef);
trace("it is:",theshape.GetUserData()); // Returns GroundSensor
shapeDef.userData = "GroundSensor";
var theshape = body.CreateShape(shapeDef);
trace("it is:",theshape.GetUserData()); // Returns GroundSensor
I've confirmed my geometry is correct and debugdraw shows the GroundSensor poking into the ground at various times. However, in contactlistener:
Code:
public override function Add(point:b2ContactPoint) : void {
if (point.shape1.GetUserData()) {
if (point.shape1.GetUserData() == "GroundSensor") {
point.shape1.GetBody().GetUserData().setGrounded(true);
trace("grounded");
} else trace("no:",point.shape1.GetUserData());
} else trace("no userdata");
if (point.shape1.GetUserData()) {
if (point.shape1.GetUserData() == "GroundSensor") {
point.shape1.GetBody().GetUserData().setGrounded(true);
trace("grounded");
} else trace("no:",point.shape1.GetUserData());
} else trace("no userdata");
No matter what happens in the simulation, this block of code only ever traces "No Userdata". I also repeat for Shape2 with similar results. I'm also getting this in the overriden "Persist" and "Remove" functions. 🙁
What's funny is I have this working perfectly for non-sensor objects. *sighs*
Can anyone give me a pointer as to where I'm going wrong?