I’m currently making a directional dmg indicator, I got the rotation part handled by using math.atan2 but I’m struggling to compute its’ positional values
This is my current code:
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local dmgIndicatorUI = script.Parent.dmgIndicator
local partDealtDmg = workspace.Part3
local absoluteSizeX = dmgIndicatorUI.AbsoluteSize.X / 2
local absoluteSizeY = dmgIndicatorUI.AbsoluteSize.Y / 2
local screenSize = camera.ViewportSize
local midScreenPos = Vector2.new(screenSize.X / 2, screenSize.Y / 2 + game:GetService("GuiService"):GetGuiInset().Y)
RunService.RenderStepped:Connect(function(dt)
local dir = (partDealtDmg.Position - hrp.Position).Unit
local camLook = camera.CFrame.LookVector
local rotationInRad = math.atan2(camera.CFrame.RightVector:Dot(dir), camLook:Dot(dir))
dmgIndicatorUI.Rotation = math.deg(rotationInRad) -- -math.deg(math.acos(camLook:Dot(dir))) * math.sign(camLook:Cross(dir).Y) (alternative but glitchy)
dmgIndicatorUI.Position = UDim2.fromOffset(midScreenPos.X + math.cos(rotationInRad) * absoluteSizeX, midScreenPos.Y + math.sin(rotationInRad) * absoluteSizeY)
end)
Basically I want the indicator to rotate AROUND the middle screen in a circle which is why i tried to use math.cos and math.sin. Although it does form a circle, it doesn’t rotate around the pivot point like I initially expected it to: https://gyazo.com/e172a52703ab1b8b59427e112c067fe8
(The main problem isn’t the rotation but the position)
Any help is solemnly appreciated!