PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Building with PGS

Building with PGS

Jul 31 2018, 4:47 PM PST 10 min

The PGS physics solver is very stable, but there are a few considerations you must take into account if you have been used to making mechanisms with the legacy physics solver.

Overconstraint

Overconstraint is a situation you will likely face when building with PGS. To understand overconstraint though, we must first know how the two physics solvers handle non-rigid joints. With the legacy physics solver non-rigid joints, such as hinges and motors, had a lot of flexibility. If a hinge was pushed hard enough, it would actually bend while still allowing for rotation. Consider the following example:

Overconstraint1.png

The black part is connected to the red part via a hinge. The red part is anchored in place so it won’t move. At the other end of the black part is a very large part which is welded to the top of the black part. If we run this game:

Overconstraint2.png

The large part at the end is very heavy, which applies a lot of force down at the end of the black part. The hinge isn’t strong enough to hold this up, so it bends. If we run this same game with PGS enabled, the assembly won’t bend, as the hinge is completely rigid (except for the axis of rotation that it allows).

Now that we see how hinges behave with both solvers, we can now look at what an overconstrained system is. In this next example, we have a sphere connected to a part via a hinge. There is another part attached to the first part which overlaps with the sphere.

Overconstraint3.png

In this situation there are two forces that will fight each other. First, the sphere and overlapping block will be pushed apart because Roblox does not allow for two solid objects to share the same space. At the same time, the hinge will attempt to keep the sphere in place. Lets see what happens to this system with the legacy solver:

Overconstraint4.png

The parts are pushed apart and the hinge bends to compensate. Now let’s see what happens with PGS:

Overconstraint5.gif

The mechanism isn’t sure what to do. It is facing a paradox, the parts cannot overlap, but the sphere also can’t move because PGS hinges don’t have any give. This causes the mechanism to bounce around, constantly under the influence of two conflicting forces.

How to tell if you have an over-constrained system

Overconstraint occurs when two parts are forced to overlap which fights a non-rigid joint. This can sometimes be subtle and hard to see, but fortunately there are settings in Studio you can use to visualize these problems. In File > Settings under ‘‘Physics’’, enable PhysicsSettings/AreContactPointsShown|AreContactPointsShown. Now, when you run your game, you will see small golden spheres wherever two parts that aren’t rigidly connected touch. In the above example, we can see contact points both where the assembly touches the ground while it bounces around, but also between the sphere and the part that it is intersecting.

Overconstraint6.png

Let’s look at another example. This very simple car works with the classic physics solver (note that the torque and turn speed of the vehicle seat are higher than the defaults). Yet it does not drive with PGS enabled.

Overconstraint7.png

Let’s turn on the contact points and hit Run. Notice how there are contacts between each of the wheels and the body of the car.

Overconstraint8.png

Unions made with SolidModeling can 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:

Overconstraint9.png

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 in the Physics tab, enable PhysicsSettings/ShowDecompositionGeometry|ShowDecompositionGeometry. Now let’s look at the wheel well (you will have to either Run and Stop your game or relaunch Studio 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.

Overconstraint10.png

If you have PhysicsSettings/AreContactPointsShown|AreContactPointsShown you can see these intersections when the game is running.

Overconstraint11.png

How to fix overconstraints

If you have a vehicle or mechanism that is overconstrained, you will have to modify your build so that parts no longer intersect. One way is to move parts so that no two parts overlap. Another solution is to disable collisions on some of the overlapping parts by disabling the BasePart/CanCollide|CanCollide property. This way the geometry of your mechanism is maintained, but there will no longer be a separation force.

Body Movers

BodyPositions and BodyGyros work slightly differently under the hood with the PGS solver enabled. If you use either of these Instances in your game, you may have to tweak them to get desired behavior. It is important to understand what the properties of BodyPosition|BodyPosition and BodyGyro|BodyGyro do in order to make changes.

Both BodyPosition and BodyGryo apply forces on their parent part to reach a desired goal. A BodyPosition|BodyPosition will try to move a part to a desired position, while BodyGyro|BodyGyro will try to move a part to a desired orientation. Both will automatically calculate how much force is needed to move their parts, but this force can be tweaked.

  • BodyPosition/P|P: P represents how aggressively the BodyMover is when trying to reach its goal. If your BodyMover doesn’t move your part fast enough to the goal, try increasing P. Conversely, if it reaches the goal too soon, try decreasing P.

  • BodyPosition/D|D: D represents how much dampening is applied to the force. You can think of this as how stable the approach is to the goal. With very little D, a BodyMover will overshoot the goal. With a lot of D, a BodyMover will slow down before it reaches the goal. If you find your BodyMover oscillates about your goal, try increasing D. If the BodyMover slows down too much as it approaches the goal, try decreasing D.

  • BodyPosition/MaxForce|MaxForce/BodyGyro/MaxTorque|MaxTorque: These properties of the BodyMover|BodyMovers cap the maximum amount of force or torque that the BodyMover can use. Note that this does not set the actual force that will be used. If D is particularly high or P is low, it is quite possible that the maximum force will not be reached.