I'm confused about some things in raycasting.
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
The first argument is start, and the second is offset. The start is where the ray is coming from and the offset is how far to check off of the start. Here are my questions:
Why subtract
tool.Handle.CFrame.pfrommouse.Hit.p? Isn't the goal to create a ray between the handle and the mouse? If so, why are we subtracting things from the mouse?What does .unit do what why multiply it by 300?
local hit, position = game.Workspace:FindPartOnRay(ray, user)
--sutff here
local distance = (position - tool.Handle.CFrame.p).magnitude
--stuff here
rayPart.CFrame = CFrame.new(position, tool.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)
So, this is CFrame.new(startPosition, lookAt). We're making the ray start at the position the hit was at, and point towards the tool. So,
- Why multiply it by -distance/2? I know the wiki says "Then we offset it by negative the distance between the points divided by two, so we end up in the middle." I know that's what it does, but why does it work like that? It does not make sense to me.

3 comments
I understand 2 and 3 but I'm still confused with number 1. What do you mean by 'displacement'? I know you said it's the direction * the distance, but I don't understand that either.
I edited the explanation to be more thorough
Thank you!