The Physics Analyzer is a tool used to detect and identify over-constrained systems in your game so you can fix them. This is very useful when making vehicles and other mechanisms using default Roblox physics and joints.
In this example, all of the brick parts are anchored. The wooden and marble parts are unanchored and overlapping. If we hit Run, the parts in the middle will experience conflicting forces. The parts are overlapping so the physics engine will create a force to separate them. However, as soon as they are pushed apart, they will hit the walls surrounding them, which creates a force to hold them together. This results in the parts moving very erratically, and one will eventually be pushed outside the walls. The result is random though, there is no way to predict how this sort of situation will resolve. In some games this sort of thing might not matter, but if these parts are part of an important mechanism, it is highly recommended to fix this sort of situation so whatever you build operates in a predictable manner.
Now that we’ve covered what an over-constrained system is, we can look at the Physics Analyzer. This tool is used to help you find where parts in your game are over-constrained. The usage is very simple. First, click on the Test tab and click on Physics:
This will popup the Physics Analyzer widget in the 3D view:
Now you can run the simulation of your game and the Physics Analyzer will try to find problems. This works with both Play and Run. If the analyzer finds a problem, it will pause the simulation and show a list of overconstraints. For example, if you run the physics analyzer with the situation outlined in the last session you will see this in the analyzer:
From here you can click on any issue in the list which will select the parts involved and will also snap the camera to look at the selection.
From here you should have a good view of the situation so you can come up with a solution to fix it. There are no one-size fits all solutions for an over-constrained system, but there are several suggestions for common cases. If the problem isn’t readily apparent, there are some other tools and views you can try (see below) you can try to diagnose the problem further.
If you want to continue running the simulation after the analyzer has paused it, you can press the play button. Note that this does not reset the camera to where it was if you clicked on an issue to focus on it.
Other Analysis Tools
The Physics Analyzer should catch most of your overconstraint problems. That said, sometimes situations arise that are subtle and hard to diagnose. There are a few more tools at your disposal that can help figure out where parts overlap.
Whenever two parts collide or overlap the physics engine creates what is called a contact point where the two parts meet. These are actually part of the system that fires
BasePart/Touched events. You can visualize these in Studio by going to File > Settings > Physics and enabling AreContactPointsShown. Now, when you run your game, you will see small golden spheres wherever two parts that aren’t rigidly connected touch.
For example, consider the following car:
This looks like a pretty simple Roblox vehicle, but it will not drive well as it contains several over-constrained systems. By turning on contact points and hitting run, we can see exactly where on the over-constrained parts the overlap is occurring:
Solid Modeling Decomposition
Unions made with Solid Modeling can also be subtle culprits of overlapping parts. When you create a union, the resulting physical geometry of the union is not a 1:1 match with the visual representation. An exact match would be too strenuous for collision physics to handle, so a simpler geometry is generated for unions for how it interacts with physics. Let’s look at the following example:
Here is a wheel well that was created with a negative cylinder and a part. Visually, it looks like the tire and the wheel well don’t touch at all. Let’s look at how physics sees this object. In your Studio settings under the Physics tab, enable
PhysicsSettings/ShowDecompositionGeometry. Now let’s look at the wheel well (simply move the union with the Move tool to see the visualization). The multicolored shapes that you see are what the physics engine sees when determining collisions. Notice how some of the edges touch or even overlap the wheels.
Visualizing contact points shows even more information (the orb at the top is where the wheel is colliding with the wheel well).
Solutions for overconstraint
There is no solution that will work for every over-constrained system, but there are several common approaches you can try depending on what you want the parts in your game to do.
One of the simplest solutions is to simply anchor the parts that are over-constrained. This is naturally only a good solution if you don’t want the parts to move at all. If the parts do need to move then another solution should be tried. But if the parts are supposed to stay stationary, there is no reason not to anchor them. Indeed, anchoring static parts is recommended as that can improve the performance of your game.
Another simple solution to fix an over-constrained system is to set the
BasePart/CanCollide property of one or more of the involved parts to false. If the part cannot collide, then the physics engine will not create any forces when the part overlaps Ssetting the wheel well’s CanCollide to false will mean the wheel well will not interact with the wheel, and the wheel will be able to roll along the ground unhindered.
If the parts in an over-constrained system cannot be anchored and all must have collisions enabled, then the recommended solution is to either move or resize the parts so that they no longer overlap.