Raycasting / maths problem

Ok so my problem is, I’m making a knife that can cut through parts, I have all the CSG stuff sorted, however I’m struggling with a ‘laser’ system which shows how the part will be cut.


I need to know how I would calculate how to size and position the red brick so it always shows the diagonal cut the knife would make.

That all kind of depends how you want it to work? Threw the following together just now by:

  1. Raycasting from Camera → Mouse, and returning the surface normal of the hit
  2. We know that the mouse position is a point on this plane so we can derive the CFrame of the plane:
CFrame.new(point, point + normal)

where point is the mouse position (or at least, the position it intersected with the object) and normal is the returned surface normal from the method ‘:FindPartOnRay()’

In regard to size, you could just get the surface of the hit as described above, and multiply the normal with the obj’s size to get the size of the cut

Uploading: image.png…

1 Like