1 decade ago by Nial
Hello ImpactJS users!
I've been using Impact to create a Box2D-powered platformer and am running into a strange problem with Box2D shape userdata. I've setup my player entity to have a collision shape as well as a secondary 'foot' sensor shape to determine when I'm stood on solid ground. The definition looks a little like this:
The idea here being that I can detect when my foot sensor stops colliding with entities. Everything is working as expected and by b2.ContactListener correctly reports when objects stop colliding with my foot sensor. The problem is that the userData I'm assigning my foot shape isn't being correctly reported.
As you can see below, the point object returned in my b2.ContactListener's Remove callback clearly contains a shape (shape2) with it's m_userData attribute set to 'feet'. However, querying the shape2 object directly reports it's m_userData as null.
I've included a screenshot of Safari's debug console performing the console.log shown below. What's going on here?!
I've been using Impact to create a Box2D-powered platformer and am running into a strange problem with Box2D shape userdata. I've setup my player entity to have a collision shape as well as a secondary 'foot' sensor shape to determine when I'm stood on solid ground. The definition looks a little like 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 idea here being that I can detect when my foot sensor stops colliding with entities. Everything is working as expected and by b2.ContactListener correctly reports when objects stop colliding with my foot sensor. The problem is that the userData I'm assigning my foot shape isn't being correctly reported.
As you can see below, the point object returned in my b2.ContactListener's Remove callback clearly contains a shape (shape2) with it's m_userData attribute set to 'feet'. However, querying the shape2 object directly reports it's m_userData as null.
I've included a screenshot of Safari's debug console performing the 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); }
1 decade ago by Nial
Hmm, it looks like that image failed to appear correctly. I'll try again:
Page 1 of 1
Page 1 of 1
« first
« previous
next ›
last »