Thursday, 15 August 2013

javascript - Box2D b2.ContactListener strangeness -



javascript - Box2D b2.ContactListener strangeness -

i've been using jonas wagner's js box2d port , running unusual problem shape userdata. i've setup entity have collision shape secondary 'foot' sensor shape determine when object on solid ground. definition looks little this:

var bodydef = new b2.bodydef(); bodydef.position.set( (this.pos.x + this.size.x / 2) * b2.scale, (this.pos.y + this.size.y / 2) * b2.scale ); this.body = ig.world.createbody(bodydef); var shapedef = new b2.polygondef(); shapedef.setasbox( this.size.x / 2 * b2.scale, this.size.y / 2 * b2.scale ); shapedef.density = 0.85; shapedef.filter.groupindex = -1; this.body.createshape(shapedef); var footshapedef = new b2.polygondef(); footshapedef.setasorientedbox( 3 * b2.scale, 3 * b2.scale, new b2.vec2(0,7*b2.scale), 0 ); footshapedef.issensor = true; footshapedef.density = 0.85; footshapedef.filter.groupindex = -1; var footshape = this.body.createshape(footshapedef); footshape.setuserdata("feet"); this.body.setmassfromshapes();

the thought here beingness can observe when foot sensor stops colliding entities. working expected , b2.contactlistener correctly reporting when objects stop colliding foot sensor. problem userdata i'm assigning foot shape isn't beingness correctly reported.

as can see below, point object returned in b2.contactlistener's remove callback contains shape (shape2) it's m_userdata attribute set 'feet'. however, querying shape2 object straight reports it's m_userdata null.

i've included screenshot of safari's debug console performing console.log shown below. what's going on here?!

var listener = new b2.contactlistener(); listener.remove = function(point) { var p = point; var s1 = p.shape1; var s2 = p.shape2; console.log(p, s1, s2); }

javascript box2d box2dweb

No comments:

Post a Comment