Hey folks, I’m not exactly how you can describe this situation other than “displacement”, so I haven’t found other topics on this.
I am working on a gun system and currently I am using raycasts to get the end position of a bullet and also have certain groups ignored.
Problem is, when I do put stuff in collision groups, it ends up displacing my bullet. Let me show you an example:
(Gray box is a bullet end position)

This is when I do not go through a collision group. (Red is the raycast’ original point).

This is when I DO go through a collision group. (Black is the expected position).
I’ll provide code if need be, but I feel like this isn’t an issue with my own code and rather just how Roblox works.
Code Just in Case
function Raycast(Player, StartPosition, EndPosition, Settings)
local RaycastParameters = RaycastParams.new() --Creates new parameters.
RaycastParameters.FilterDescendantsInstances = {Player.Character, workspace.RaycastIgnoreList} --Prevents the player from being in the raycast.
RaycastParameters.CollisionGroup = "IgnoreList"
RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist --Blacklists.
local Raycast = workspace:Raycast(StartPosition, (EndPosition - StartPosition).Unit * Settings.MaxDistance, RaycastParameters)
return Raycast
end
local RaycastResult = Raycast(Player, Origin, EndingPoint, Settings)
if RaycastResult then
local Part = Instance.new("Part")
Part.Parent = workspace
Part.Position = RaycastResult.Position
print(Part.Position)
Part.Anchored = true
Part.Size = Vector3.new(0.2,0.2,0.2)
DebrisService:AddItem(Part, 4)
end
Here’s what I used to configure collision groups:
local function IfStatements(part)
if part:IsA("BasePart") and part.Name ~= "Terrain" then
if part.Transparency > 0.7 then
PhysicsService:SetPartCollisionGroup(part, "IgnoreList")
elseif part.Material == Enum.Material.Glass then
PhysicsService:SetPartCollisionGroup(part, "IgnoreList")
end
end
end
for i, part in pairs(workspace:GetDescendants()) do
IfStatements(part)
end
for i, part in pairs(ReplicatedStorage:GetDescendants()) do
IfStatements(part)
end
for i, part in pairs(ServerStorage:GetDescendants()) do
IfStatements(part)
end
