So I have this arrow that I want to face a certain part. The problem is I want it to move relative to where the camera is facing, now the actual arrow. So if the player looks left but the part is towards the right, the arrow faces right. This picture might make it more obvious:
I tried this but it obviously only looks in the same direction regardless of where you look:
game:GetService("RunService").RenderStepped:connect(function()
local p = script.Parent.Arrow:GetPrimaryPartCFrame().p
script.Parent.Arrow:SetPrimaryPartCFrame(CFrame.new(p.X, p.Y, game.Workspace.Part.Position))
end)
Sorry if I’m explaining this poorly. Help is appreciated!
2 Likes
Not sure about this, but I think you need to adjust the cframe relative to the cameras cframe.
Which is literally the title…
I actually got it to work!
local cam = game.Workspace.CurrentCamera
game:GetService("RunService").RenderStepped:connect(function()
script.Parent.Arrow:SetPrimaryPartCFrame(CFrame.new(script.Parent.Arrow:GetPrimaryPartCFrame().p, game.Workspace.Part.Position * cam.CFrame.LookVector))
end)
I took the desired part’s position and multiplied it by the camera’s LookVector. It’s on now!
Nevermind, it only partially works. It seems like it’s always facing a random position instead of what I want. Help please…
First of all, what and where is this arrow? Is it just a part in a ViewportFrame
, and if so, what is its position in the frame?
Arrow is a model in ViewportFrame. The frame’s position is 0,0,1,0
with an AnchorPoint of 0,1
. I can attach a repro if that will help
I should’ve read the topic!!!
Try this:
local viewportFrame = --the arrow's ViewportFrame, I'm guessing script.Parent
local VFcam = viewportFrame.CurrentCamera
local cam = workspace.CurrentCamera
game:GetService("RunService").RenderStepped:Connect(function()
VFcam.CFrame = cam.CFrame.Rotation * CFrame.new(0, 0, 10)
--change 10 to how far away you want the camera to be.
local turnCF = CFrame.lookAt(cam.CFrame.Position, game.Workspace.Part.Position)
script.Parent.Arrow:SetPrimaryPartCFrame(turnCF.Rotation)
end)
This will make the arrow model’s primary part point its front face/LookVector
toward Part
from the camera.
5 Likes
I appreciate it. The arrow now faces the same direction consistently, but it still isn’t the right way. Can change anything to make it face a different direction?
/ would simply just resize and rotate the PrimaryPart
along its X,Y, and Z axes until it faces the right direction.
But, you can also try multiplying (turnCF - turnCF.Position)
by CFrame.Angles(0,math.pi/2,0)
, or CFrame.Angles(math.pi/2,0,0)
or any CFrame.Angles
constructor with positive or negative math.pi/2
in X Y or Z until it faces the right direction.
2 Likes
Thank you so much for the help! I finally got it working
1 Like