Hello Everyone!
I need help with creating a joint when ContactEvent is triggered. I keep on getting an error which I so far only understand that it has got something to do with creating the joint. This class is in a Sensor, so what I want to do is to make the sensor contact a box and only create one joint for the sensor and box. This sensor is attached to a BoxMan.
Thank you In advance! XD
I need help with creating a joint when ContactEvent is triggered. I keep on getting an error which I so far only understand that it has got something to do with creating the joint. This class is in a Sensor, so what I want to do is to make the sensor contact a box and only create one joint for the sensor and box. This sensor is attached to a BoxMan.
Thank you In advance! XD
Code:
public override function create():void {
reportBeginContact = true;
reportEndContact = true;
fixedRotation = true;
super.create();
addEventListener(ContactEvent.BEGIN_CONTACT, handleContact);
contacts = new ContactList();
contacts.listenTo(this);
}
public function handleContact(e:ContactEvent):void {
var b:BodyShape = Util.findAncestorOfClass(e.target as DisplayObject, BodyShape, true) as BodyShape;
trace(e.target); //traces: Sensor not Box
if(b) {
createHeroJoint(b);
}
}
public function createHeroJoint(B:BodyShape):void {
var j:joint = new joint();
trace("!");
j.x = this.body.x; j.y = this.body.y;
j.bodyShape1 = this.body;
j.bodyShape2 = b.body;
j.type = 'Revolute';
world.addChild(j);
}
reportBeginContact = true;
reportEndContact = true;
fixedRotation = true;
super.create();
addEventListener(ContactEvent.BEGIN_CONTACT, handleContact);
contacts = new ContactList();
contacts.listenTo(this);
}
public function handleContact(e:ContactEvent):void {
var b:BodyShape = Util.findAncestorOfClass(e.target as DisplayObject, BodyShape, true) as BodyShape;
trace(e.target); //traces: Sensor not Box
if(b) {
createHeroJoint(b);
}
}
public function createHeroJoint(B:BodyShape):void {
var j:joint = new joint();
trace("!");
j.x = this.body.x; j.y = this.body.y;
j.bodyShape1 = this.body;
j.bodyShape2 = b.body;
j.type = 'Revolute';
world.addChild(j);
}