Collision detection with Gleed2d paths

Topics: Developer Forum
May 9, 2012 at 2:08 AM
Edited May 10, 2012 at 12:39 PM

 

Solved. I wasn't converting properly.
May 9, 2012 at 8:39 PM

I also use GLEED2D for my game. Here is the code I use to create my path bodies.

        public override void CreateBody(Item item)
        {
            base.CreateBody(item);
            PathItem path = item as PathItem;

            for (int i = 0; i < path.WorldPoints.Length; i++)
            {
                path.WorldPoints[i] = path.WorldPoints[i].ConvertToWorldUnits();
            }

            for (int i = 0; i < path.WorldPoints.Length - 1; i++)
            {
                AddPathSegment(base.PhysicsEngine.World, path.WorldPoints[i], path.WorldPoints[i + 1]);                
            }
        }

        private void AddPathSegment(World world, Vector2 start, Vector2 end)
        {
            EdgeShape edge = new EdgeShape(start, end);
            base.Body = new Body(world);
            base.Body.CreateFixture(edge);
            base.Body.Friction = 5f;
            base.Body.CollidesWith = Category.All;
            this.worldPoints.Add(start);
            this.worldPoints.Add(end);
            base.ID = base.Body.BodyId;

            base.PhysicsEngine.PhysicsBodies.Add(base.ID, this);
        }

 

May 10, 2012 at 12:04 AM

I still can't get that to work.. I did it but I am not colliding with anything. Any other suggestions? I had to add extra things to make that code compile, so maybe I did something wrong along the way. I really need to get this to work...

I believe my rectangles are getting drawn around my sprites correctly, so I think the problem is with the polygon getting created around the path.