What would be a good approach to cut a line (or curve) at a specific point (let's say we use the mouse pointer to detect the position of the cut).

enter image description here

The curves you see in the image above, are Bezier curve generated using the LineRenderer and have a PolygonCollider2D attached that covers the entire curve (taking the width set to the LineRenderer into consideration).

Imagine a game like Cut the Rope or Fruit Ninja, where you use the mouse pointer to cut the wires. I already implemented the cut detection algorithm, so I know the point where my wire needs to be cut. I would like to know how can I snap the wire in two and add some sort of animation.

  • \$\begingroup\$ I don't think you can achieve this easily with Bezier Curves. Games that I'm aware that have ropes or anything can make curves or be cut actually are bunch of segments connected, and not a single line. \$\endgroup\$
    – DH.
    Jul 29 '16 at 13:28
  • \$\begingroup\$ I could create my own Wire class that's made up of multiple segments, each segment being a game object with a LineRenderer. I can then detect which segment was cut. I still can't wrap my head around how could I animate the cut. \$\endgroup\$ Jul 29 '16 at 13:30
  • \$\begingroup\$ By animating you mean what? An "slashing" animation or the ropes moving after removing a segment? \$\endgroup\$
    – DH.
    Jul 29 '16 at 13:38
  • \$\begingroup\$ Since this are some sort of bomb wires, I think the animation should be the line splitting in two at that point and move the parts away from each other, they don't need to drop. Adding the slash effect should be pretty straight forward. \$\endgroup\$ Jul 29 '16 at 13:42

I'd instantiate (via an object pool) a GameObject with a RigidBody and SphereCollider attached at each of the points along the line. Then use Rigidbody.AddExplosionForce to the two objects nearest the cut. Create an array of the GameObjects transforms in order from the start of the wires to the cut point & in each update cycle set the corresponding line renderer position to that that transform position. You could tweak the mass of the rigidbodies to suit how you want the wires to fall. Would need some fine tweaking but should get the job done.

  • \$\begingroup\$ Sorry forgot to mention, but I guess you realised what i was getting at already - update the line renderers points to the instantiated game objects positions in each update. I'll modify my post. \$\endgroup\$
    – Absinthe
    Jul 29 '16 at 20:02
  • \$\begingroup\$ Thanks again! Will try it out and come back with a demo :) \$\endgroup\$ Jul 29 '16 at 20:06
  • \$\begingroup\$ Cool, hope it works :) \$\endgroup\$
    – Absinthe
    Jul 29 '16 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.