Im making an fps game, i’m trying to make it like PF or Arsenal, in those games, the further away you are from the target, the less damage it will do, i know how to measure the distance
Calculating Distance Variable:
local Distance = (BarrelPos - MousePos).magnitude
but i can’t think of the maths that i’d need to do to calculate what damage the player should do at the set range.
RayCast Code:
local function Raycast(player,BarrelPos,MousePos)
local ray = workspace:Raycast(BarrelPos,(MousePos - BarrelPos).unit * 5000,RayCastParam)
local Distance = (BarrelPos - MousePos).magnitude
if ray then
local humanoid = ray.Instance.Parent:FindFirstChild("Humanoid")
local Enemy = game.Players:GetPlayerFromCharacter(ray.Instance.Parent)
if CanShoot == true then
if humanoid and not humanoid:IsDescendantOf(player.Character) then
if ray.Instance.Name:lower() == "headhitbox" or ray.Instance.Name:lower() == "head" then
HitMarkerSound:Play()
HitMarkerImage.ImageTransparency = 0
FireEvent:FireServer(humanoid,HeadShotDamage)
print("headshot")
elseif ray.Instance.Name:lower() == "bodyhitbox" or ray.Instance.Name:lower() ~= "head" then
HitMarkerImage.ImageTransparency = 0
HitMarkerSound:Play()
FireEvent:FireServer(humanoid,Damage)
print("body shot")
end
end
if Enemy then
end
end
end
end