How Does This Directional Damage Indicator Work?

Here it is in action:

Code:

local RNS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local frame1 = script.Parent.frame

RNS.Heartbeat:Connect(function()
	local mousePos: Vector2 = UIS:GetMouseLocation()
	local disp: Vector2 = mousePos - frame1.AbsolutePosition
	local angle: number = math.deg(math.atan2(disp.Y, disp.X)) + 90
	
	frame1.Rotation = angle 
end)

This already works, I’m just curious.

How does this work? Why do you need to add ‘90’ to the angle to make it work right? I’m only recently starting trigonometry so this is all new to me.

2 Likes

Is the arrow already oriented prior to runtime? If it is the 90 degree offset is necessary.

1 Like

What do you mean by ‘oriented prior to runtime’? Why is the 90 degree offset necessary?

The 90 degree offset is most likely necessary because the actual image uploaded to Roblox is facing the “wrong direction” so they have to add the offset.

1 Like