Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can Someone Explain CFrame.p and CFrame.Unit?

Asked by
Fad99 286 Moderation Voter
4 years ago

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:

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?

1 answer

Log in to vote
2
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

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: ```lua Part = workspace:WaitForChild("Part") print(Part.Position) --Prints position print(Part.CFrame.p) --Prints position

0
Thank you! Fad99 286 — 4y
Ad

Answer this question