So, I've been working on a pistol, until now the bullet dropoff was not a big worry, although this has changed due to me visualising bullets. This leads me to the problem, I've tried a semi working fix for it, which is just to cast the ray (the pistol uses raycast) a bit down (how much it is casted down is determined by the distance between the ray's start and end divided by 62.
Although it does work, it looks really bad, the bullets just seem like they're normally going down with no dropoff, I can't figure out how to make it better though, I have done some searching and did realize you could just have a lot of smaller rays in an arc (all combined the rays are the same length as the straight ray would be), which would work and look realistic. Although the problem is I can't figure out how I'd do that, and make my bullet travel along them. Any ideas?
MAIN SCRIPT (It has the raycast and bullet visualisation part in it, the part I need help with pretty much should end at around line 49)
local Present = true
local TweenService = game:GetService("TweenService")
local tab = {workspace.IgnoreModel}
local first = true
local Hole
local Part,Position,Normal
script.Parent.BulletEvent.OnServerEvent:Connect(function(Player, FromP, ToP, BulletPos)
if script.Parent.AbleToShoot.Value == true then
if first == true then
table.insert(tab, Player.Character)
first = false
end
local RayCast = Ray.new(FromP,(ToP-FromP).unit*500)
Part,Position,Normal = game.Workspace:FindPartOnRayWithIgnoreList(RayCast,tab,false,true)
local Dist = (ToP-FromP).magnitude
if not Dist then Dist = 300 end
Hole = game.ReplicatedStorage:FindFirstChild("GlockBulletHole"):Clone()
-------------------------------------------------------------------
local projectile = script.Parent.Bullet.Projectile:Clone()
projectile.Parent = game.Workspace
projectile.CFrame = CFrame.new(BulletPos, ToP)
projectile.Tracer.Enabled = true
local Info = TweenInfo.new(
(ToP-script.Parent.Parts.BE.Position).magnitude/457,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Position = ToP
}
local BulletTween = TweenService:Create(projectile, Info, Goals)
BulletTween:Play()
if (ToP-script.Parent.Parts.BE.Position).magnitude <= 1000 then
game.Debris:AddItem(projectile, (ToP-script.Parent.Parts.BE.Position).magnitude/457)
elseif (ToP-script.Parent.Parts.BE.Position).magnitude > 1000 then
game.Debris:AddItem(projectile, 2.2)
end
end
-------------------------------------------------------------------
wait((ToP-script.Parent.Parts.BE.Position).magnitude/457)
if Part ~= nil then
Hole.Parent = Part.Parent
Hole.Position = Position
Hole.Material = Part.Material
Hole.Color = Part.Color
Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
table.insert(tab, Hole)
local breakoffParts = {Instance.new("Part", workspace),Instance.new("Part", workspace),Instance.new("Part", workspace),Instance.new("Part", workspace)}
for i, v in pairs(breakoffParts) do
v.Position = Hole.Position
v.Orientation = Vector3.new(math.random(0,360),math.random(0,360),math.random(0,360))
local mesh = Instance.new("SpecialMesh", v)
mesh.MeshType = Enum.MeshType.Wedge
v.Size = Vector3.new(0.05,0.05,0.05)
v.Material = Part.Material
v.Color = Part.Color
v.Transparency = Part.Transparency
v.Reflectance = Part.Reflectance
v.Velocity = Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
table.insert(tab, v)
game.Debris:AddItem(v, 2)
end
if Part.Material == Enum.Material.Slate or Part.Material == Enum.Material.Sand or Part.Material == Enum.Material.Pebble or Part.Material == Enum.Material.Brick or Part.Material == Enum.Material.Concrete or Part.Material == Enum.Material.Cobblestone or Part.Material == Enum.Material.Granite or Part.Material == Enum.Material.Marble or Part.Material == Enum.Material.Wood or Part.Material == Enum.Material.WoodPlanks or Part.Material == Enum.Material.Plastic or Part.Material == Enum.Material.SmoothPlastic then
Hole.Dust.Enabled = true
end
if Part.Material == Enum.Material.Wood or Part.Material == Enum.Material.WoodPlanks then
Hole.Splinter.Enabled = true
end
if Part.Material == Enum.Material.Glass then
if Part.CanCollide == true then
Part.CanCollide = false
local BreakSound = script.Parent.Glass:Clone()
BreakSound.Parent = Part
BreakSound:Play()
game.Debris:AddItem(BreakSound, BreakSound.TimeLength)
Part.CanCollide = false
if Part:FindFirstChild("Shatter") == nil then
local eft = script.Parent.Shatter:Clone()
eft.Parent = Part
eft.Enabled = true
eft.Color = ColorSequence.new(Part.Color)
eft.Transparency = NumberSequence.new(Part.Transparency)
Hole.H1.Transparency = 1
Hole.H2.Transparency = 1
end
else
Hole.H1.Transparency = 1
Hole.H2.Transparency = 1
end
end
if Part.Material == Enum.Material.Slate or Part.Material == Enum.Material.Pebble or Part.Material == Enum.Material.Brick or Part.Material == Enum.Material.Concrete or Part.Material == Enum.Material.Cobblestone or Part.Material == Enum.Material.Granite or Part.Material == Enum.Material.Marble then
Hole.Rock.Enabled = true
Hole.Rock.Color = ColorSequence.new(Part.Color)
end
if Part.Material == Enum.Material.ForceField then
Hole.Energy.Enabled = true
Hole.H1.Transparency = 1
Hole.H2.Transparency = 1
end
if Part.Material == Enum.Material.Plastic or Part.Material == Enum.Material.SmoothPlastic or Part.Material == Enum.Material.Foil then
Hole.Plastic.Enabled = true
Hole.Plastic.Color = ColorSequence.new(Part.Color)
end
if Part.Material == Enum.Material.Metal or Part.Material == Enum.Material.DiamondPlate or Part.Material == Enum.Material.CorrodedMetal then
Hole.Sparks.Enabled = true
end
if Part.Material == Enum.Material.Grass then
Hole.Grass.Enabled = true
Hole.Grass.Color = ColorSequence.new(Part.Color)
end
if Part.Material == Enum.Material.Fabric then
Hole.Fabric.Enabled = true
Hole.Fabric.Color = ColorSequence.new(Part.Color)
Hole.TornFabric.Enabled = true
Hole.TornFabric.Color = ColorSequence.new(Part.Color)
end
Hole.H1.Color3 = Part.Color
Hole.H2.Color3 = Part.Color
local Weld = Instance.new("Weld")
Weld.Part0 = Part
Weld.Part1 = Hole
Weld.C0 = Part.CFrame:Inverse()
Weld.C1 = Hole.CFrame:Inverse()
Weld.Parent = Hole
if Part and Part.Parent:FindFirstChild("Humanoid") ~= nil then
for i, v in pairs(breakoffParts) do
v:Destroy()
end
local bleed = script.Parent.Bleeding:Clone()
bleed.Parent = Part.Parent:FindFirstChild("Humanoid")
bleed.Value = true
local damage = 10
if Part.Name == "Head" then
damage = math.random(50,70)
bleed.BleedDamage.Value = 42
end
if Part.Name == "Torso" or Part.Name == "HumanoidRootPart" then
damage = math.random(20,22.5)
bleed.BleedDamage.Value = 50
end
if Part.Parent:IsA("Accessory") then
if (Part.Position-Part.Parent.Parent.Head.Position).magnitude > (Part.Position-Part.Parent.Parent.Torso.Position).magnitude then
damage = math.random(20,25)
bleed.BleedDamage.Value = 50
elseif (Part.Position-Part.Parent.Parent.Head.Position).magnitude < (Part.Position-Part.Parent.Parent.Torso.Position).magnitude then
damage = math.random(50,70)
bleed.BleedDamage.Value = 42
end
end
Part.Parent.Humanoid:TakeDamage(damage)
Hole.BloodCloud.Enabled = true
Hole.Bleed.Enabled = true
Hole.Blood.Enabled = true
Hole.Dust.Enabled = false
Hole.Splinter.Enabled = false
Hole.Rock.Enabled = false
Hole.Plastic.Enabled = false
Hole.Grass.Enabled = false
Hole.Fabric.Enabled = false
Hole.H1.Transparency = 1
Hole.H2.Transparency = 1
Hole.B1.Transparency = 0.4
Hole.B2.Transparency = 0.4
else if Part.Parent.Parent:FindFirstChild("Humanoid") and Part ~= nil then
for i, v in pairs(breakoffParts) do
v:Destroy()
end
local bleed = script.Parent.Bleeding:Clone()
bleed.Parent = Part.Parent:FindFirstChild("Humanoid")
bleed.Value = true
local damage = 10
if Part.Name == "Head" then
damage = math.random(50,70)
bleed.BleedDamage.Value = 42
end
if Part.Name == "Torso" or Part.Name == "HumanoidRootPart" then
damage = math.random(20,25)
bleed.BleedDamage.Value = 50
end
Part.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
Hole.BloodCloud.Enabled = true
Hole.Bleed.Enabled = true
Hole.Blood.Enabled = true
Hole.Dust.Enabled = false
Hole.Splinter.Enabled = false
Hole.Rock.Enabled = false
Hole.Grass.Enabled = false
Hole.Plastic.Enabled = false
Hole.Fabric.Enabled = false
Hole.H1.Transparency = 1
Hole.H2.Transparency = 1
Hole.B1.Transparency = 0.4
Hole.B2.Transparency = 0.4
end
end
Hole.Dust.Color = ColorSequence.new(Part.Color)
end
if Part then
if Part.Parent ~= nil then
game.Debris:AddItem(Hole,15)
end
end
end)
