What do I want to achieve?
I want a part to face away from the camera despite the characters orientation. Eg. If i look at my characters face the part should be behind the character. Just as it is in this video:
What is the issue?
When the characters orientation is any other than 0,0,0 it offsets the part so that the part isnt facing away from the camera.
This is the script
wait(1)
local player = game.Players.LocalPlayer
local part = Instance.new("Part")
part.Anchored = false
part.Massless = true
local char = player.Character or player.CharacterAdded:Wait()
part.Parent = char
local root = char.HumanoidRootPart
local cam = workspace.CurrentCamera
local weld = Instance.new("Weld",part)
weld.Part0 = root
weld.Part1 = part
while wait(0.1)do
weld.C0 = CFrame.new(Vector3.new(0,0,0),Vector3.new(0,0,0))
weld.C0 = CFrame.new(weld.C0.Position + cam.CFrame.LookVector.Unit * 5, weld.C0.Position + cam.CFrame.LookVector.Unit)
end
What solutions have I tried so far?
I have tried asking in discord servers and now im asking here.
I have also tinkered with this for about a day now and still cant figure it out. I think its because the HumanoidRootPart is rotating and therefor the weld.C0 is also rotating but I have tried subtracting the HumanoidRootPart lookVector from the weld.C0 but it still doesnt work.
Feel free to copy the script, paste it in a localscript inside StarterCharacterScripts and tinker around with it yourself:) Any help is appreciated!
Thank you good sir! It finally worked!. You have my graditute. Just a quick question. Where have you learnt this? By exploring CFrame yourself in some baseplate or by learning something like linear algebra? Or is there another source i’ve never heard of?
I learned of these techniques by experimenting with systems that use CFrames, like custom camera controllers, custom character controllers, and concepts that require manipulation of space in general.
The best advice I can give is to practice. Try making a system that uses CFrames heavily (like those first two examples above) so you can feel comfortable with them. In my experience, you don’t need a high-level understanding of math, only some good spatial reasoning.
Then again, I have a high-level understanding of math… I don’t know if what I’m saying is biased, so take it with a grain of salt I guess.