This project has moved. For the latest updates, please go here.

How to do "cut the rope"

Dec 4, 2010 at 2:17 PM

Hi i am a newbie with farseerphysic engine . Now i tried to do game similar "cut the rope" on iphone

i have a problem. how i remove some shape between rope " cut rope " or how i remove joint between my rope

This is my rope code

   Path path = new Path();   
   path.Add(new Vector2(200, 200));   
   path.Add(new Vector2(200, 202));  
   path.Add(new Vector2(200,204));  
   path.Add(new Vector2(200, 206));   
   path.Add(new Vector2(200, 208));   
   path.Closed = true;   
   List<FarseerPhysics.Collision.Shapes.Shape> shapes = new List<FarseerPhysics.Collision.Shapes.Shape>(2);  
    shapes.Add(new FarseerPhysics.Collision.Shapes.PolygonShape(PolygonTools.CreateRectangle(2.5f, 2.5f, new Vector2(0.1f, 0), 0)));  
  shapes.Add(new FarseerPhysics.Collision.Shapes.CircleShape(1.5f));  
    List<Body> bodies = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shapes, BodyType.Dynamic, 15, 0.01f);
    PathManager.AttachBodiesWithRevoluteJoint(world, bodies, new Vector2(2.5f, 2.5f), new Vector2(2, -2.5f), false, false);

or anyone have some another method to do this ?

Could you suggest me

thank you


Dec 4, 2010 at 5:13 PM
Edited Dec 4, 2010 at 5:13 PM

i just know how to do that



thank you

Dec 4, 2010 at 9:48 PM

You have a list of bodies returned from the EvenlyDistibuteShapesAlongPath() method. When the rope is cut, you could remove one of those bodies using World.RemoveBody().

In FPE 3.2 the AttachBodiesWithRevoluteJoint() method returns the list of revolute joints created. This might be more suiting for your needs, but for now you will have to replicate the functionality. You can use the latest version of the PathManager as a reference.

Dec 5, 2010 at 2:10 PM

Thank you genbox

now    i can do same like "cut the rope " but i have some problem with line intersection with bodies.

i use rectangles for map all of rope bodies and use mouse position to create rectangle for check which rope should remove .

but this method have problem

- rectangle can t rotate follow bodies

- i don t know how to use line ( mouse click start and last ) to cut the rope

do you have another method to advice me ?



Dec 5, 2010 at 2:43 PM

If the cut is straight only, you simply build a small AABB and query the world for overlapping fixtures. (World.QueryAABB()) Then you remove the bodies the AABB overlaps.

If you need something more accurate you should do a polygon vs. polygon collision test (a line with 2 points in FPE 3.0 is considered a polygon) on each of the bodies returned from the AABB query.