Shell Collisions

Hello, I’ve run into an issue with roblox collisions and I was wondering what I could do to fix it.

I made this artillery gun some 2 days ago for my group and can’t figure out how to fix the bullets not exploding on impact.

Note: This works sometimes, if the bullet ricochets and hit’s something else it blows up.

I’ve lowered the bullet velocity which it is shot at and it appears to work better but I’m not sure how I can keep the velocity and the collision fix

local parent = script.Parent

local function explode(part)
	local explode_1 = script.Parent.explode_1
	explode_1:Play()
	parent.CanCollide = false
	local explosion = Instance.new("Explosion")
	explosion.DestroyJointRadiusPercent = 0.07
	explosion.BlastRadius = 50
	explosion.BlastPressure = 300
	explosion.Parent = game.Workspace
	explosion.Position = parent.Position
	wait(1)
	parent:Destroy()
end
parent.Touched:Connect(explode)

Thanks,
– Luke

Maybe from the speed of the bullet it’s clipping through parts,
Are you using BodyVelocity or Raycasting?

If you’re using BodyVelocty, try to save its last position every half a second or lower(By using heartbeat or stepped) and raycast the last position and it’s current position, if it hits something, then explode otherwise continue

Try using fastcast, it uses raycasting

1 Like

Using .magnitude could work, for example:

while wait() do
     for _, v in pairs(game.Workspace:GetDescendants()) do
          if v:IsA("Part") and (v.Position - parent.Position).magnitude <= 5 then
               explode()
          end
     end
end
2 Likes

.Touched is a very buggy function, sadly, a better way to go about hit detections is via raycasting.

I put that in the script and modified it to how its intended but its still somewhat delayed, how could I fix this?

I was thinking about that but I use .Velocity to propel the bullet, meaning the bullet drop is controlled by gravity so the shell doesn’t face the way its going, if you could tell me how I can make it do that I’d appreciate it. Is there a way I can send a raycast in every direction?

you should use “.Magnitude” instead of “.magnitude”

It’s because the while wait() has a 0.03 second delay for each time you check the distance, and honestly, I’m not sure how to fix that kind of thing.

I agree with @imdaros and @RVCDev, raycasting is the way to go with bullets.

1 Like

How do I make the shell look the way its going?

  • If you mean getting the direction of where the shell is facing you need to do this:
    Using the bullet’s CFrame value, LookVector, which is the forward-direction component of the CFrame’s orientation. You would do the main part of the bullet (make sure the front face of the part is facing in the direction you want the bullet to travel in, you can do this by using a decal to see where the front is) .LookVector * TotalDistance (which I would put as 100000).

  • Else if you are talking about the how to make the bullet face in the direction its going:
    You can use the CFrame.new function like this CFrame.new(Bullet.Position, Destination.Position), this should make the bullet face the position entered as the second parameter.

Hope this helps :smiley:

it was the second thing you said, thanks SO much