I need the a unit vector that points in the direction the camera is facing but is also based on the input.
In my code I have a table called input that has an x and a y value. These values can both be either -1, 0, or 1. So if the x input was -1 it would get left on that axis.
This is what the vector would look like without it being camera relative:
Vector3.new(input.X, 0, input.Y)
This is what it looks like with that, but I want that green vector line to be relative to the camera.
Sorry if this doesn’t make sense, I am having a hard time explaining it.
This shouldn’t be too hard, I created a simple script which can make a specific part keep the same orientation as the camera.
For all axes
local Camera = workspace.CurrentCamera
local Part = workspace.Part
Camera:GetPropertyChangedSignal"CFrame":Connect(function()
Part.CFrame = CFrame.new(Part.Position)*CFrame.fromOrientation(Camera.CFrame:ToOrientation())
end)
For only on the Y axis
local Camera = workspace.CurrentCamera
local Part = workspace.Part
Camera:GetPropertyChangedSignal"CFrame":Connect(function()
local y = select(2,Camera.CFrame:ToOrientation())
Part.CFrame = CFrame.new(Part.Position)*CFrame.fromOrientation(0,y,0)
end)
This shouldn’t be too hard to add,
All axes but accounting for the offset
local input = {X=0,Y=1,Z=-1}
local Camera = workspace.CurrentCamera
local Part = workspace.Part
Camera:GetPropertyChangedSignal"CFrame":Connect(function()
Part.CFrame = CFrame.new(Part.Position)*CFrame.fromOrientation(Camera.CFrame:ToOrientation())*CFrame.Angles((input.X/2)*math.pi,(input.Y/2)*math.pi,(input.Z/2)*math.pi)
end)
Only the y axis but accounting for the offset
local input = {X=0,Y=1,Z=-1}
local Camera = workspace.CurrentCamera
local Part = workspace.Part
Camera:GetPropertyChangedSignal"CFrame":Connect(function()
local y = select(2,Camera.CFrame:ToOrientation())
Part.CFrame = CFrame.new(Part.Position)*CFrame.fromOrientation(0,y,0)*CFrame.Angles((input.X/2)*math.pi,(input.Y/2)*math.pi,(input.Z/2)*math.pi)
end)