I want to make it so when a player has been hit a GUI will pop up showing the direction of where they have been hit like in call of duty this what I mean down below
Here’s the simplest script you can use
local c = game:GetService('Players').LocalPlayer
local p = workspace:WaitForChild('Part')
local h = c.Character:WaitForChild('HumanoidRootPart')
local cam = workspace.CurrentCamera
while wait() do
local Facing = h.CFrame.LookVector
local Vector =(h.Position-p.Position).unit
local MathVariable=math.deg(math.acos(Facing:Dot(Vector)))
script.Parent.Rotation=-MathVariable*math.sign(Facing:Cross(Vector).Y)
end
Make sure this a local script in your gui
Here’s the ID you can use for the imageLabel: rbxassetid://6076629567
1 Like
This is the way I do it and it works perfectly for me:
local myPosition = myHRP.Position
local enemyPosition = enemyHRP.Position
local camCFrame = camera.CFrame
local flatCFrame = CFrame.lookAt(myPosition, myPosition + camCFrame.LookVector * Vector3.new(1, 0, 1)) -- basically just creates a cframe that has the position of your character's rootpart and the rotation of the camera WITHOUT the up/down rotation
local travel = flatCFrame:Inverse() * enemyPosition -- find the travel distance from the flatCFrame to the enemy position (cf:inverse() * v3 is equivalent to cf:PointToObjectSpace(v3))
local rot = math.atan2(travel.Z, travel.X)
imageOnScreen.Rotation = math.deg(rot) + 90
17 Likes
Does this come with a GUI? And where do I put it??
1 Like
Ok the imageOnScreen variable should be set to an imageLabel thats inside of a gui
2 Likes
Ok I’ll message you if I do something wrong
2 Likes