Putting an accessory on a player is easy enough, especially when I get them from free models. However I’m having a hard time making a preview for hats in a ViewportFrame. Hats don’t automatically move to the head when you put them as a descendant of a ViewportFrame.
My only idea was to position the hat like (for a R6 character)
however that seems to not move the hat into the right location (somewhere inside the head, not on top for a regular hat). Do I need to add another fixed offset?
There are several Vector3’s inside of an Accessory that define it’s position. These include:
AttachmentForward,
AttachmentPos,
AttachmentRight,
and AttachmentUp
If it’s inside the head you can simply add " * CFrame.new(0, desired y, 0)" of course there are easier ways to do this but that requires a plugin that I don’t have the link to.
local h = game.ReplicatedStorage.Accessories.Cowboy
print(h.AttachmentPoint==CFrame.fromMatrix(h.AttachmentPos, h.AttachmentRight, h.AttachmentUp ,-h.AttachmentForward))
true
I don’t know how the solution in my original post is any different from what you are suggesting.
I tried that, but it’s also wrong on another axis, and it’s not a universal solution (a custom offset for one hat does not work for any other hat).
I’m almost certain ViewportFrames don’t simulate physics in any way in which case assemblies will never update. Creating a weld (which is what that post does) will not position the hat at all.
I had a look in an alive character’s hats and it turns out the AttachmentPoint is the C1 of the hat weld, while the C0 is always 0, 0.5, 0. So doing hat.Handle.CFrame = head.CFrame * CFrame.new(0, 0.5, 0) * hat.AttachmentPoint:inverse() did the trick.