Fragmenting a part

I am trying to make a destruction physics system

the method i am attempting is shown below through the diagram:
(NOTE: We are going to ignore the welding part of this system for the sake of keeping this
post concise)

the “impact” is represented as a red circle on the wall. The idea is that the wall is then split into 5 parts.
Sadly my highschool diploma only allows me to find the size and position of the “fragments” on a 2 dimensional level, meaning that if the wall is not perfectly aligned with the world, everything breaks.

So far ive managed to do one thing which is to find how far out from the center the “impact” is located by substracting the positions of the center of the part (i’ve already compensated for the fact the part isn’t a flat piece of paper) to the position of the impact. In a 2d environment i can simply decompose the vector and add half the size of the wall itself and the impact zone (2 pieces of data i already have). The problem is that the vector i obtain is rotated according to the world and not the part itself. In summary, i just need some help finding a way to turn this three dimensional vector into a two dimensional one relative to the part.

1 Like

I seem to have figured out a partial solution, despite the fact it doesn’t work as soon as the wall becomes tilted. Seems to be that somewhere, some coordinates are swapped, problem is i have no clue which ones.

Turns out, you can turn that 3d vector into a cframe, and then turn the cframe around so it faces the origin of the world and conveniently gives you both the x and y coordinates you need.

Here is some sample code of the manipulation:

local position = result.Position
		local surfacecenter = result.Instance.Position + result.Instance.CFrame.LookVector*result.Instance.Size.Z/2

		 local difference = surfacecenter - position
                 local length = difference.Magnitude

		local rotate = CFrame.new(Vector3.new(0,0,0),difference)
		local radx,rady,radz = rotate:ToOrientation()
	        local wall = result.Instance.Orientation
		local orientation = Vector3.new(math.rad(-wall.X),math.rad(-wall.Y),math.rad(-wall.Z))+ Vector3.new(radx,rady,radz)
		
		local makessense = CFrame.fromOrientation(orientation.X,orientation.Y,orientation.Z)
		local destination = makessense.LookVector*length