I have a crate in my 2D game, made of a 2D rigidbody and a box collider. How can i make a player be able to slice it with a laser, so that the result will be 2 separate rigidbodies?
You have to convert your collider to lines after that you find point of intersection laser with lines. Then you will be able create two or more polygon colliders. I guess, you use sprite renderer. You may convert your sprite to mesh, and slice mesh like slice collider and do triangulation. Spoiler: code Code (CSharp): public static bool intersection(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2, out Vector2 point) { point = Vector2.zero; float x1 = a1.x; float y1 = a1.y; float x2 = a2.x; float y2 = a2.y; float x3 = b1.x; float y3 = b1.y; float x4 = b2.x; float y4 = b2.y; float t = 0; float xa = 0; float ya = 0; if (Mathf.Abs((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)) < 0.0001) { return false; } else { t = ((y3 - y1) * (x3 - x4) - (x3 - x1) * (y3 - y4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)); if ((t >= 0) && (t <= 1)) { xa = x1 + t * (x2 - x1); ya = y1 + t * (y2 - y1); if (((x3 - xa) * (x4 - xa) <= 0) && ((y3 - ya) * (y4 - ya) <= 0)) { point = new Vector2(xa, ya); return true; } else { return false; } } else { return false; } } }