✓ Accepted answer
There are multiple ways to do this depending on what you're looking for but I think that this should be okay:
local flag = workspace.Target
local cam = workspace.CurrentCamera
local image = script.Parent.ScreenGui.ImageLabel
local imageId = "http://www.roblox.com/asset/?id=11458585"
local Render = game:GetService("RunService").RenderStepped
while Render:wait() do
local vector, onScreen = cam:WorldToViewportPoint(flag.Position)
local x1,y1 = vector.X,vector.Y
local x2,y2 = image.Position.X.Offset, image.Position.Y.Offset
local xlength,ylength,zlength = x1-x2,y1-y2,vector.Z
local hypotenuse = math.sqrt(xlength*xlength + ylength*ylength)
local UnitX,UnitY,UnitZ = xlength/hypotenuse, ylength/hypotenuse,zlength/hypotenuse
local Normalized2dDirection = Vector3.new(UnitX,-UnitY,UnitZ)
local angle = math.deg(math.acos(Normalized2dDirection:Dot(cam.CFrame.UpVector)))
local cross = Normalized2dDirection:Cross(cam.CFrame.UpVector)
local angle2 = math.sign(cross.Z) * angle
if onScreen then
image.Image = ""
else image.Image = imageId
image.Rotation = angle2
end
end
This is my first time trying to do anything like this by myself so I had to learn while doing this. It has been quite the ride, but I think that it turned out okay (although I know that it's a bit glitchy & could be improved.
Honestly, I think that it looks better if you remove
if onScreen then
image.Image = ""
else image.Image = imageId
image.Rotation = angle2
end
and just replace it with image.Rotation = angle2.
Here are some links to help: Link1 Link2 Link3.
2 comments
This helped a lot, thanks!
Would also really appreciate if you could upvote my answer thanks :)