Trouble connecting path to a body

Topics: Developer Forum
Aug 4, 2011 at 2:49 PM

I'm attempting to create a "crane" that can pick up objects. The crane comes down from the center of a ship. I created a path using advanced demo 2 and added a joint to connect it to the ship. However I'm getting some crazy behavior from the crane rope. I tried to adjust the mass of the ship and mass of the crane but I still get odd behaviors, such as the rope tangling up. Here's the code:

	    ////////////
            /* PLAYER */
            ////////////
            
            //load image for player
            polygonTexture = ScreenManager.Content.Load<Texture2D>("Sprites/playerShip_02");
            
            //an array to hold data from texture
            uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];

            //transfer data to array
            polygonTexture.GetData(data);

            //find vertices that make up outline for shape in the texture
            Vertices textureVerts = PolygonTools.CreatePolygon(data, polygonTexture.Width, false);

            //The tool return vertices as they were found in the texture.
            //We need to find the real center (centroid) of the vertices for 2 reasons:

            //1. To translate the vertices so the polygon is centered around the centroid.
            Vector2 centroid = -textureVerts.GetCentroid();
            textureVerts.Translate(ref centroid);


            //2. To draw the texture in the correct location
            polygonOrigin = -centroid;

            //simplify the vertices found in texture
            textureVerts = SimplifyTools.ReduceByDistance(textureVerts, 4f);

            //since the poly is concave, partition into secreal smaller convex polys
            List<Vertices> list = BayazitDecomposer.ConvexPartition(textureVerts);

            //scale vertices from graphics space to sim space
            Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * scale;
            foreach (Vertices vertices in list)
            {
                vertices.Scale(ref vertScale);
            }

            //create single body with multiple fixtures
            player = BodyFactory.CreateCompoundPolygon(World, list, 1f, BodyType.Dynamic);
            player.BodyType = BodyType.Dynamic;
            player.IgnoreGravity = true;
            player.Mass = 5000f;
           
            ////////////////
            /* CRANE ROPE */
            ////////////////
            Path cranePath = new Path();
            cranePath.Add(player.Position);
            cranePath.Add(new Vector2(player.Position.X,player.Position.Y + 5));
            cranePath.Closed = false;

            Vertices box = PolygonTools.CreateRectangle(0.075f, 0.5f);
            PolygonShape shape = new PolygonShape(box, 0f);

            craneBodies = PathManager.EvenlyDistributeShapesAlongPath(World,
                                                cranePath,
                                                shape,
                                                BodyType.Dynamic,
                                                20);
            craneBox = new Sprite(ScreenManager.Assets.TextureFromShape(shape,
                                                MaterialType.Dots,
                                                Color.Black,
                                                1f));
            //attach first fixture to player
            JointFactory.CreateRevoluteJoint(World,
                                player, 
                                craneBodies[0], 
                                player.Position);
            
            foreach (Body crane in craneBodies)
            {
                player.IgnoreCollisionWith(crane);
                crane.IgnoreCollisionWith(player);
                crane.Mass = 0f;
                crane.Inertia = 500f;
            }

            PathManager.AttachBodiesWithRevoluteJoint(World,
                                    craneBodies,
                                    new Vector2(0f, -0.5f),
                                    new Vector2(0f, 0.5f),
                                    false,
                                    false);

Aug 4, 2011 at 2:58 PM

Edit:

Basically I want to end of the rope to remain facing down. As it stands now, sometimes it curls up. I eventually want to put a "grabber" at the end of the rope to pick up object: Here's a pic of what's happening:

Photobucket

Aug 4, 2011 at 6:59 PM

I would say attach a weight to the end of the rope, with the same mass as the crane you intend to attach later. You'll get a more realistic idea of what your rope will do then.