Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I fix my bullets visualizing at the wrong place at high speeds?

Asked by
Axenori 124
3 years ago

So, I have made a raycast pistol. I use tweening to move the bullet along the ray. Although I have encountered a problem, when I set the bullets to move along quickly (as they should) they do not visualize at the correct place, being several studs off. I tried tinkering with the trail in the block which is being moved along, but realized it's in the script, if I lower it to lower speeds the bullets visualize great, and are not off. Is there any way to fix this or is this just due to the roblox engine and is out of my control?

Gyazo GIF of normal (fast speed) bullets: https://gyazo.com/b693caffa5c605839ef9d5f52e9e4d89

Gyazo GIF of slowed down bullets: https://gyazo.com/24b701898a1c559bcf28b1654d218b44

Script, I've highlighted the bullet visualization part between 2 lines so it's easier to find:

local Present = true
local RS = game:GetService("RunService")
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
 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)

Answer this question