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

Place a part on face of another part ?

Asked by
Voltoxus 248 Moderation Voter
8 years ago

How would I go about placing a thin layer of snow on top of an parts top face, I would just make the script clone the part at change the add to the Z value of the CFrame, but the parts are cframed and different sizes.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

Object Space

CFrames describe a position and orientation in space.

Actually, they describe the position and orientation relative to some reference frame.

If you have some reference CFrame and some part, then you can say

relative = reference:toObjectSpace( part.CFrame )

to get a relative CFrame which describes the offset from reference to part.CFrame.

To 'apply' this relative change, you can use

absolute = reference:toWorldSpace(relative)
    -- or  = reference * relative -- (same thing)

A Part's Object Space

For a Part, the origin (0, 0, 0) is the Part's CFrame. The Top surface is at CFrame.new(0, part.Size.y/2, 0).

Thus we can get a CFrame with the same orientation as Part, but at its Top surface, using

top = part.CFrame * CFrame.new(0, part.Size.y/2, 0)

If you want to put a part on top of it that's 0.2 studs thick, then that part's center would have to be 0.1 studs further out:

snow.Size = part.Size * Vector3.new(1, 0, 1)
snow.CFrame = part.CFrame * CFrame.new(0, part.Size.y/2 + 0.1, 0)
Ad

Answer this question