Bus Scripting w/ Collision Groups

I’m trying to script a bus that has motorized doors. Although, I need the door model to clip through the body model. Using CollisionGroups is quite janky since if I need to duplicate buses and link them to the same CollisionGroup. As well as a limit to how many CollisionGroups you can make.

I was thinking of using “NoCollisionConstraint”, but I couldn’t link it by group, considering that the doors will need to clip through many parts. My existing code is using CollisionGroups which isn’t as effective.

function initalize()
		game:GetService("PhysicsService"):SetPartCollisionGroup(script.Parent, "Misc")
		game:GetService("PhysicsService"):SetPartCollisionGroup(script.Parent.Parent.Body, "Body")
		game:GetService("PhysicsService"):CollisionGroupSetCollidable("Body", "Misc", false)

I’m trying to find a most efficient way for the doors, wheels, foldable seats, and more not collide with the body itself, since I’m using HingeConstraints for part movement, and I know it will spaz if collision isn’t turned off between the Body model and the part itself.
Misc and Body are the two groups that needs to have collision off for each other.

Just use a for loop for all descendants of the models and put them in two separate collision groups.
Then, make the collision groups not collide with each other. Pretty straightforward if using Instance:GetDescendants().

Keep in mind that if you do something such as make Body not collide with itself, then different buses may be able to go through each other. This can be resolved by making your own little box colliders for the bus (highly recommended) that are less complex than the bus mesh/body itself.
Also note that collision groups can be a one-time assignment, as they will persist even if the model is cloned (so it doesn’t have to be done every time you wish to spawn a new bus for example).

1 Like

There’s no need to create new collision groups every single time.

Make them as part of your game’s initialisation and their interaction, and then just add the parts to the relevant group when spawning the bus.

I assume your doors are close to being in line with the wall, so it’s not like you’ll ever have a case where another bus drivers through a bus’ doors, because the wall around it would stop the bus.

1 Like

Adding onto this, you could even do what I said in the console/command bar in studio or with a collision group editing plugin. Also,