How can I align a part to the camera?

How can I make this align orientation align it self with the camera? I want to use this because the scripted way is way to rigid and sharp.
I put it on single attachment because it seems the best path for an align orientation.

1 Like

Maybe this can help:

Sorry, but I’m not trying to get what face of a part I’m looking at.

mm you can make it single attachment, and then store camera lookvector as variable. Then just add that lookvector to your alignOrientation cframe

local cameraLookVector = workspace.CurrentCamera.CFrame.LookVector
myAlignOrientation.CFrame = CFrame.new(myPart.Position + cameraLookVector)

So I put your script in a local script (for the current camera thing), but I somehow got this.

Is Part Anchored=true and CanCollide=false?

The align orientation won’t work if it’s anchored, because the script is not setting the part’s cframe, but the attachments.
The align orientation is also definitely strong enough to move the part.

Aha, I’ve found the error - using workspace.Part.Postion + cframeLookVector in the CFrame constructor is incorrect. See if the below works:

    local camera = game.Workspace.CurrentCamera
    local attachment = game.Workspace.Part.Attachment0
    game:GetService("RunService").RenderStepped:Connect(function(delta)
        local cameraLookVector = camera.CFrame.LookVector
        attachment.CFrame = CFrame.new(attachment.Position) * CFrame.Angles(0,math.pi/4,0):VectorToWorldSpace(cameraLookVector )
        
    print("Camera Look Vector:", cameraLookVector, "  Attachment Look Vector:", attachment.CFrame.LookVector)
    end)

cc How to rotate a direction? (Look vector)

I do put this in a while true right?
I got this error, and the variables were also correct.

Don’t put that in a while loop :sweat_smile: copy + paste just my code into the file. I also made an error, try this instead:

    local camera = game.Workspace.CurrentCamera
    local attachment = game.Workspace.Part.Attachment0
    game:GetService("RunService").RenderStepped:Connect(function(delta)
        local cameraLookVector = camera.CFrame.LookVector
        attachment.CFrame = CFrame.new(attachment.Position, attachment.Position + cameraLookVector)
        
        print("Camera Look Vector:", cameraLookVector, "  Attachment Look Vector:", attachment.CFrame.LookVector)
    end)

We are almost there!
I think somehow it’s completely inverted, but it’s almost there.

Sorry for the constant videos, I’m just not good at explaining things, so this is just easiest for me.

On the contrary, videos are much more useful than verbal explanations with stuff like this :+1:

I’d mess around with changing the + to a - in the CFrame constructor. Also look into rotating CFrames

1 Like

my bad. dont use cframe.new use cframe.lookat

part.AlignOrientation.CFrame = CFrame.lookAt(part.Position, part.Position + game.Workspace.CurrentCamera.CFrame.LookVector)

video of it working

5 Likes

Yes! Thank you so much Joel and Onebeets, yall helped me get the solution!
This ended up being the final script:

local camera = game.Workspace.CurrentCamera
local attachment = game.Workspace.Part1.Attachment0
local part = workspace.Part1
game:GetService("RunService").RenderStepped:Connect(function(delta)
	local cameraLookVector = camera.CFrame.LookVector
	part.AlignOrientation.CFrame = CFrame.lookAt(part.Position, part.Position + cameraLookVector)
end)
1 Like