How would I attach a part above the character’s head, but also maintain orientation (0,0,0) regardless of the character’s rotation? (Is there like any type of weld or constraint to achieve this?)
No, welds and weld constraints both use CFrames as offset, so rotation is applied as well.
If you want to keep the position same but not the rotation, you can either use a BodyPosition or set the position yourself. Using a BodyPosition would cause a movement that isn’t quite attached.
You can use a connection or a loop to keep the position attached by an offset, since the offset itself changes according to the head, you can use the CFrame:VectorToWorldSpace() method
local RunService = game:GetService("RunService")
local player = ... -- As achievable in context
local character = player.Character
local part = ...
local offset = Vector3.new(0, 5, 0) -- 5 studs above the head for example
RunService.Heartbeat:Connect(functon()
local headCF = character.Head.CFrame
part.Position = headCF.Position + headCF:VectorToWorldSpace(offset)
end)
I was afraid of that… I was hoping to avoid doing something like this for performance
There’s no large performance hit by such connections, if you anchored the part as well (which is what you probably have as of now), the physics cost of the part gets cut down heavily.
I think you can probably use an AlignPosition constraint to have it stay above their head without rotating. Just ensure that you set RigidityEnabled
to true
.
Tried, that won’t work. I’ll probably have to do what’s suggested above.
What was the issue? Did it rotate?
Yes, it does, probably due to gravity (and anchoring it will not work with bodymovers/etc). I’ll probably just move an anchored part I guess, that seems like the best solution.
EDIT: BodyGyro can be used to keep rotation.