[SOLVED] Attempting to make a damage pointer for my gun game

So im currently developing a gun game, and im trying to make an ImageLabel point towards where you took damage from. The ImageLabel is a 1:1 ratio in size, so there isnt any position calculations to be done. All i need is for it to rotate correctly.

Currently, i have the pointer disabled due to it pointing in the complete wrong direction every time i try it.

Ive been looking everywhere for a few weeks now for something to help me, tried the only one i found, which got me the issue i wrote above.

Heres my current code:

local NewDamagePointer = script.Parent.DamagePointer:Clone()
	NewDamagePointer.Parent = script.Parent.DamagePointers

	-- issue starts here
	local directionalVector = (Character.HumanoidRootPart.Position-SavedPos)
	local Rotation = Character.HumanoidRootPart.CFrame.LookVector:Dot(directionalVector)
	NewDamagePointer.Rotation = Rotation * 180
	-- issue ends here
	
	NewDamagePointer.Visible = true
	local Tween = TweenService:Create(NewDamagePointer, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {ImageTransparency = 1, ImageColor3 = Color3.fromRGB(100, 0, 0)})
	Tween:Play()
	Debris:AddItem(NewDamagePointer, 1.5)

Video if the pointer not working correctly:

1 Like

You do know you are rotating it by 180 which will make it face the other way

Edit: where are you getting shot from in the vid??

I am aware of that, and i have tried it without the multiplication, and it was exactly the same, but well, rotated the other way.
Edit: In the video, its supposed to be pointing towards the grey box right in front of me

I got it to work correctly.

please explain how you fixed your problem!

2 Likes

Heres the code that works:

function NewDamageIndicatorUI(SavedPos)
	-- SavedPos = the location of the person who shot at you
	local NewDamagePointer = script.Parent.DamagePointer:Clone()
	NewDamagePointer.Parent = script.Parent.DamagePointers
	
	local Facing = Character.HumanoidRootPart.CFrame.LookVector
	local Vector = (Character.HumanoidRootPart.Position-SavedPos).unit
	local MathVariable = math.deg(math.acos(Facing:Dot(Vector)))
	NewDamagePointer.Rotation = -MathVariable*math.sign(Facing:Cross(Vector).Y)
	
	NewDamagePointer.Visible = true
	local Tween = TweenService:Create(NewDamagePointer, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {ImageTransparency = 1, ImageColor3 = Color3.fromRGB(100, 0, 0)})
	Tween:Play()
	Debris:AddItem(NewDamagePointer, 1.5)
end

Edit: The damage indicator image must be a 1:1 size ratio for this to work, and when the indicators Rotation is set to 0, it should be pointing down.