Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can Someone Explain CFrame.p and CFrame.Unit?

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

✓ Accepted answer

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:

Part = workspace:WaitForChild("Part")
	print(Part.Position) --Prints position
	print(Part.CFrame.p) --Prints position

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.