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

Raycast not hitting all the time?

Asked by 2 years ago

I made a meteor power system for our school project game and i tried using raycasting to make the explosion more accurate but the raycast doesn't seem to hit all the time. Anyways here's the code :

wait(1)
local CanCollide = true
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")

game.ReplicatedStorage.RenderStepped.OnServerEvent:Connect(function(Player)
    local Raycast = workspace:Raycast((script.Parent.CFrame * CFrame.new(0,0,-4)).Position,(script.Parent.CFrame * CFrame.new(0,0,-25)).Position)
    if (Raycast) and CanCollide == true then
        if Raycast.Instance.CanCollide == true then
            CanCollide = false
            local Explosion = game.ReplicatedStorage.Explosion:Clone()
            Explosion.Parent = workspace.Debris
            Explosion.Anchored = true
            Explosion.CanCollide = false
            Explosion.CFrame = CFrame.new(Raycast.Position,Raycast.Position + Raycast.Normal)
            Explosion.Color = Raycast.Instance.Color
            Explosion.Size = Vector3.new(0,0,0)
            Explosion.Material = "Neon"
            Explosion.CastShadow = false
            local Tween = TweenService:Create(Explosion,TweenInfo.new(2,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(100,100,100)})
            Tween:Play()
            local Tween = TweenService:Create(Explosion,TweenInfo.new(4,Enum.EasingStyle.Quart,Enum.EasingDirection.Out,0,false,0),{Transparency = 1})
            Tween:Play()
            Debris:AddItem(Explosion,3)
            for i = 0,13,1 do
                local Splash = game.ReplicatedStorage.SplashExplosion:Clone()
                Splash.Parent = workspace
                Splash.CFrame = Explosion.CFrame
                Splash.Velocity = (CFrame.new(Raycast.Position,Raycast.Position + Raycast.Normal) * CFrame.new(math.random(-100,100),math.random(-90,100),math.random(-100,100))).Position
                Splash.ParticleEmitter.Color = ColorSequence.new{
                    ColorSequenceKeypoint.new(0,Raycast.Instance.Color),
                    ColorSequenceKeypoint.new(1,Color3.fromRGB(235, 106, 0))
                }
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

local Raycast = workspace:Raycast(script.Parent.Position,script.Parent.CFrame.LookVector*25)

maybe try this instead

0
or you could just use touched instead Verbalase_notreal 23 — 2y
0
touched events are worse they don't hit everytime plus they hit before hitting the ground IEntity_303I 80 — 2y
Ad

Answer this question