polygon slope collision issue

Hi,

I've been working with Box2DFlash for a couple of weeks and despite how awesome it is I appear to be doing it wrong 😕

I've created a rectangle with a slope on top and made it a polygon, but when objects collide with it they just sort of "drift" through it with weird results. I figured it was my code that was the problem so I put the shape in the test bed, but I'm still getting the same issue. I've been snooping around the forums and the web but can't seem to locate any more info that can help with this.

Anyone feel like giving me a hand? Here's the test bed code I knocked together from the stacked boxes test:

Code:
/*
package TestBed{
   
   
   
   import Box2D.Dynamics.*;
   import Box2D.Collision.*;
   import Box2D.Collision.Shapes.*;
   import Box2D.Dynamics.Joints.*;
   import Box2D.Dynamics.Contacts.*;
   import Box2D.Common.*;
   import Box2D.Common.Math.*;
   
   //TODO_BORIS: Remove
   use namespace b2internal;
   
   public class TestBob extends Test{
      
      public function TestBob(){
         
         // Set Text field
         Main.m_aboutText.text = "Why won't you work?";
         
         // Add bodies
         var fd:b2FixtureDef = new b2FixtureDef();
         var sd:b2PolygonShape = new b2PolygonShape();
         var bd:b2BodyDef = new b2BodyDef();
         bd.type = b2Body.b2_dynamicBody;
         //bd.isBullet = true;
         var b:b2Body;
         fd.density = 1.0;
         fd.friction = 0.5;
         fd.restitution = 0.1;
         fd.shape = sd;
         
         // Create ramp
         var vertices:Array = new Array(
            new b2Vec2(100 / m_physScale, -75 / m_physScale),
            new b2Vec2(-100 / m_physScale, -25 / m_physScale),
            new b2Vec2(-100 / m_physScale, 75 / m_physScale),
            new b2Vec2(100 / m_physScale, 75 / m_physScale));
         sd.SetAsArray(vertices, vertices.length);
         fd.density = 0;
         bd.type = b2Body.b2_staticBody;
         bd.userData = "ramp";
         bd.position.Set(200 / m_physScale, 260 / m_physScale);
         b = m_world.CreateBody(bd);
         b.CreateFixture(fd);
         
         // Create ball
         var cd:b2CircleShape = new b2CircleShape();
         cd.m_radius = 40/m_physScale;
         fd.density = 2;
         fd.restitution = 0.2;
         fd.friction = 0.5;
         fd.shape = cd;
         bd.type = b2Body.b2_dynamicBody;
         bd.userData = "ball";
         bd.position.Set(250/m_physScale, 100 / m_physScale);
         b = m_world.CreateBody(bd);
         b.CreateFixture(fd);
         
      }
      
      
      //======================
      // Member Data
      //======================
   }
   
}


Thanks 🙂

-Bob
Without looking at your code, it's a winding issue - try reversing the order you list your vertices. Should be fine.

I've created a few hundred Box2D objects manually and I still order vertices wrong...
Awesome, it's working now 😀

I had tried putting the vertices in clockwise before but I guess I messed the order up 😳

Thanks!

Original thread: https://box2d.org/forum/viewtopic.php?t=5080