How exactly do I manually position a hat on a character?

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)

hat.Handle.CFrame = head.CFrame * hat.AttachmentPoint

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?

1 Like

There are several Vector3’s inside of an Accessory that define it’s position. These include:
AttachmentForward,
AttachmentPos,
AttachmentRight,
and AttachmentUp

The developer wiki explains more in detail on what exactly these vectors define. Accessory | Documentation - Roblox Creator Hub

3 Likes

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.

2 Likes
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).

1 Like

I believe this might help your problem as it welds the hats properly client-sided which should work for ViewportFrames: Humanoid:AddAccessory does not work with FE from a LocalScript - #4 by TheGamer101

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.

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.