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 6 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:

01local model = script.Parent.Parent
02model.PrimaryPart = model.Base
03model.Base.Fire.Enabled = true
04 
05local explosionPart = script.Parent
06while true do
07    wait()
08    script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,.1,0))
09script.Parent.Touched:connect(function(hit)
10   if hit:IsDescendantOf(script.Parent.Parent) == false then
11        local explosion = Instance.new("Explosion", game.Workspace)
12explosion.Position = explosionPart.Position
13explosionPart.Parent:Destroy()
14 
15 
16end
17end)
18end

1 answer

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

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

1local PhysicsService = game:GetService("PhysicsService") --This gets the service
2 
3PhysicsService:CreateCollisonGroup("[name]") --Creates a collisiongroup
4 
5PhysicsService:CollisonGroupSetCollidable("[group]", "[group]", [true/false]) --Defines collison properties between 2 groups
6 
7PhysicsService: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