Im trying to learn the how to make a raycasting weapon by looking at a developer article, but i cant understand a line of code in there. The code is as followed:
1 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p -tool.Handle.CFrame.p).unit * 300 ) |
What i dont understand is where it says tool.Handle.CFrame.p
and (mouse.Hit.p -tool.Handle.CFrame.p).unit
I just dont know what .p
is and .Unit
i, can someone please explain?
CFrames hold a LookAt and Position value, so CFrame.p
is short for CFrame.Position
.
Unit
refers to “Unit vector”.
Although, I’ve never seen this used before.
Learn a bit more about it here:
https://developer.roblox.com/articles/CFrame-Math-Operations
https://developer.roblox.com/api-reference/datatype/CFrame
Example Code:
1 | Part = workspace:WaitForChild( "Part" ) |
2 | print (Part.Position) --Prints position |
3 | print (Part.CFrame.p) --Prints position |