How does getting the front face work?

Hello,

I been doing research and I have fell on this topic that I am interested in learning. Although I don’t fully understand how this works and how I would use it in the future for my works.

I’m trying to get a cube’s front face. Here is what I seen so far.

local frontFaceCF = cube.CFrame * CFrame.new(0,0,-cube.Size.Z/2)

I don’t understand how that is getting the front face…
I have also been doing research on look vectors but still nothing understood.

Would anybody mind giving code samples or explaining me how it works?

Thanks in advance!

-cube.CFrame.LookVector will give you the direction of your front face. Multiply that with the Z size divided by 2 and add it to the position and you’ll get the front face’s position.

cube.CFrame.Position -cube.CFrame.LookVector*cube.Size.Z/2

Could you explain more? it’s good explanation but my potato brain doesn’t understand too much math,

A part’s CFrame represents the center of the part, what your code is doing is getting the center of the part (by doing part.CFrame) and then moving it half it’s size along the z axis (getting the side of the part).

Think of it like this: The part is 3 studs long. The part’s cframe represents the center of it. (The cframe is 1.5 studs from it’s left side and 1.5 studs from it’s right side). Now you’re moving the cframe half the part’s size (1.5 studs) along the z axis, so now the cframe is located at the side of the part.

2 Likes

So what you just explained get’s the part’s corner?

1 Like

What he explained gets the position of the front face

2 Likes

You have any code samples I can see?

I just explained what your code does.

1 Like

I misread your post.

Imagine taking an already present offset and continue offsetting it. That is exactly what this line does.

Imagine a CFrame as an offset from the 0,0,0 position with a 0,0,0 rotation.
That second value is the forwards direction.

If your base CFrame contains a 10,5,2 position and a 30,0,0 rotation, offsetting it by 0,0,-1 will give you where the front face is located.

Note that while the top and right are positive on their axes, the front is negative.

2 Likes