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

How do I avoid model collision with itself?

Asked by 5 years ago

I have a rocket that when something touches the tip, it explodes. However, when I drop it, it explodes because it collided with itself. How do I tell it not to explode if they collide with a part of a rocket? here's the script:

local model = script.Parent.Parent
model.PrimaryPart = model.Base
model.Base.Fire.Enabled = true

local explosionPart = script.Parent
while true do 
    wait()
    script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,.1,0))
script.Parent.Touched:connect(function(hit)
   if hit:IsDescendantOf(script.Parent.Parent) == false then
        local explosion = Instance.new("Explosion", game.Workspace)
explosion.Position = explosionPart.Position
explosionPart.Parent:Destroy()


end
end)
end

1 answer

Log in to vote
1
Answered by
Joshument 110
5 years ago
Edited 5 years ago

So there is something called "CollisionGroups" and they can disable collision between another collison group or itself. It kinda goes like this:

local PhysicsService = game:GetService("PhysicsService") --This gets the service

PhysicsService:CreateCollisonGroup("[name]") --Creates a collisiongroup

PhysicsService:CollisonGroupSetCollidable("[group]", "[group]", [true/false]) --Defines collison properties between 2 groups

PhysicsService:SetPartCollisonGroup(part, group) --adds a part to the collision group

All you would need to do is make sure the rocket parts are in a collisiongroup and add the rocket to that group when it spawns.

Hope this helped! You can also find a post about this on the devforums, but I forgot the link.

Ad

Answer this question