For my game, I’m creating a sticky grenade that, when collides with anything, sticks to it, then explodes shortly. I check for collision on the client, with network ownership set to the player. But, I’m having a problem with detecting the collision, it isn’t accurate.
You can see that it goes through the part and then detects the collision, sometimes even missing the part and going straight through. I’ve tried:
- GetPartsInPart
- Touched
- Raycasting (although I don’t think I explored this enough so it isn’t out of the picture yet)
None of these seem to accurately detect collision, which is weird, since it’s on the client.
Code (LocalScript)
local CM = require(game:GetService("ReplicatedStorage").CerberusModule)
local RunService = game:GetService("RunService")
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local grenadeModel = script.Parent
local grenade = grenadeModel.Hitbox
local stickPos = grenade.StickPosition
local stickOri = grenade.StickOrientation
local attachment0 = grenade.Attachment0
local attachment1 = grenade.Attachment1
local knockbackAttachment = grenade.KnockbackAttachment
local position = script:WaitForChild("position").Value
local hitPos = script:WaitForChild("hitPos").Value
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {grenadeModel, char}
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
CM:CreateKnockback(grenade.KnockbackAttachment, CFrame.new(position, hitPos).LookVector * 120)
RunService.RenderStepped:Connect(function()
local hitPos = grenade.Position
for _,v in pairs(workspace:GetPartsInPart(grenade, overlapParams)) do
attachment1.Parent = v
attachment1.WorldPosition = hitPos
attachment1.Orientation = grenade.Orientation
stickPos.Enabled = true
stickOri.Enabled = true
RemoteEvent:FireServer("PlaySound", grenade.Hit)
script.Disabled = true
end
end)
This is my current code. Any help is appreciated.