Hey programmers, today i’ve tried making a damage indicator, think of it like COD, apparently i get consecutive errors and it doesnt really work, i would love if someone assist me or guide me by code or maybe brief explanation of how to make a damage indicator like cod, thanks!
Can you show your current code so we can correct errors?
i ended up deleting the entire thing sadly
If you deleted it how are we supposed to help you?
giving me a guide of how would u make it bruh
I would appreciate if you don’t act that aggressive with me, but before I give you an idea of how to make it could you explain what you mean by a COD damage indicator (any screenshots, etc).
My guess is:
- Whenever someone shoots you, make it so that it saves the position of the guy that shot you.
- Create a directional vector by subtracting the position of the guy who shot you from your humanoid root part position.
- Project the derived directional vector onto your humanoid root parts look vector using HumanoidRootPart.CFrame.LookVector:Dot(directionalVector)
- Create a damage indicator in the gui and update it’s rotation by the number that the projection returned. For it to rotate properly, multiply the returned number by 180. To spherically move the indicator around the center of your screen, just add the returned projection number to both the X and Y offsets of the gui object and dont forget to multiply it by like 10 or 20 so that it is visible.
- To make it so that the damage indicator displays the correct angle even if you move, correct it each render step until it’s gone.
So you mean like those red lines when you start getting damaged right? Well here’s how I would do it. I think you’re trying to have four red circles around the screen as you lose more and more health.
At 75 health, the first red circle should be fully visible.
At 50 the second red circle should be fully visible.
At 25 the third red circle should be fully visible.
At 0 the fourth red circle should be fully visible
This means the scale from 75 to 100 should be condensed to a scale of 0 to 1, and then inverted since we are finding the transparency, not the visibility.
Then we should also check if each gui should already be transparent, for example if the currenthealth was 75 then the first gui circle should be fully transparent.
Here’s a commented Demo I made using this concept:
Testing.rbxl (24.6 KB)
EDIT: I might have misunderstood what you meant, I think Weldify got it right.
i will test but yeah i will use both methods to see what im looking for, thanks!
I might have sent you the old version, if it’s not working fully ask me so I can reopen studio and see where the right version is.
(The old version might also have outdated comments so it might not be that clear)
mind explaining by code, so i can understand better, i think i didnt got what u meant, sorry!, however i will make ur guess my solution
I think @Weldify means something like this:
local humanoidRootPart = --[the player's humanoid rootpart directory]
local gui = --[the gui]
local runService = game:GetService("RunService")
local humanoidPos = Vector3.new(position here) -- the player's humanoidrootpart position
local shotFrom = Vector3.new(position here) -- the position of who shot the player
local direction = (humanoidPos - shotFrom) -- the directional vector
local dir = humanoidRootPart.CFrame.LookVector:Dot(direction) -- the LookVector
local function updateGui() -- function to update the gui
gui.Rotation = dir * 180 -- rotate the gui
gui.Position = Udim2.new(0, dir, 0, dir) * 10 -- this part i'm not so sure
end
runService.RenderStepped:Connect(updateGui) -- update the gui every frame
-- this script could be incorrect, but this is what I interpreted from his explanation
the actual set up doesn’t look like this, just a guide of what’s needed
so thats place inside the screengui am i correct?