I am currently implementing piercing to my gun engine, but got into some math problem,
I want to get the length of the intersectionand get A into B (A is origin, B is the point were it gets out of the part) . More details there :

I need some help with the maths, I have the Normal Surface, Position (A), the axis hit (X, Y, Z) and CFrame. Adding C to origin A would get me to goal B.
Thanks !

I think you’d need the width of the wall. in which case it’s:

local wallVec = -norm
local p = A.Unit:Dot(wallVec)
local coeff = 1 / p
local C = A.Unit * coeff * wall.Width
local B = A + C

p is the percentage of the wall that the unit vector goes through. therefore you need to divide one by the percentage to get the coefficient for the full distance.

if you have two unit vectors A and B it actually becomes the percentage that A covers B. think about it: the percentage covered is usually p = (A dot B) / |B| but since |B| is just 1, it’s simply p = A dot B. in this case, A is the direction of the bullet and B is the reversed normal of the wall.

now to find the coefficient of A.Unit that would become C. we can invert a percentage by using it to divide 1. for example, if x is 50% of y, then 1 / 0.5 = 2; you have to multiply x by 2 to equal y. the same rule applies to vectors.

then we have C = A.Unit * (1 / p). however, this would only work on a wall that was one stud long since wallVec is one stud long. we have to multiply it by the width of the wall. so finally: