AssemblyCenterOfMass does not register anchored parts

I wanted to use the new AssemblyCenterOfMass property in my game and i discovered a bug that prevents me from using this new property.

Any welded part that is anchored will NOT be registered by this property.

Fully anchored plane:

Unanchored plane:

I have also noticed that the center of mass doesn’t even change for some blocks.

I have anchored the plane in the picture and unanchored the selected block at the back, it made absolutely no difference.

Steps to reproduce:

  1. Start a test server with 0 players
  2. Unanchor the plane
  3. Anchor the plane

The yellow ball will show you where the AssemblyCenterOfMass is.
AssemplyBugPlace.rbxl (26.1 KB)

2 Likes

This is as expected based on the following properties of assemblies:

Here are some screencaps that should help illustrate these rules. The colored outlines around the parts signify which assembly they are a part of, matching colors means same assembly. (You can enable this visualization yourself in File > Studio Settings > Physics > Are Assemblies Shown).

Here’s an assembly of 4 parts, welded together with WeldConstraints:
image
If I was to set one of these parts as anchored, there would be no change to the assembly (other than the root part potentially changing). All the welds would still be active, and the whole assembly is implcitly anchored. Parts welded to an anchored part are basically still anchored, as they can’t move.

Here’s what happens when I anchor 2 parts, the middle and top right part in this case:
image
Now, we have two assemblies. The top right (yelllow) part became it’s own assembly, and you can see that the weld has become inactive (WeldConstraint.Acive = false). That’s because you can’t have an active weld between two anchored parts/assemblies. It doesn’t mean anything to do so. Also since we have two assemblies, there are two different center of masses. The three green parts should all have the same AssemblyCenterOfMass value, while the yellow part will have a different one, equal to its position in this case.

Now, let’s anchor all the parts:
image
Each part is now it’s own assembly, and all welds are inactive. Each part will have a different AssemblyCenterOfMass value.

I hope that helps clear things up! We are working on a more in-depth article for the dev hub that should cover everything, but feel free to ask more questions here.

5 Likes

But what if i wanted to know the AssemblyCenterOfMass before unanchoring a car as an example?
There would be no way of knowing this except for custom code, i’d also still have to check every single part to see if a part is anchored or not, which means this is less efficient than my custom code.

Why do you need to have all the parts anchored in the first place?

If all the parts are anchored, then each part is an assembly. If you want the center of mass of an arbitrary set of parts, then yeah you would need custom code for that.

2 Likes

In my game it is difficult to know whether there are anchored parts inside of an assembly.

There are anchor blocks people can place in my games which anchors their creation on a button press, if i have to calculate the center of mass while the creation is anchored, i’d have to cycle through the whole creation to check for anchored parts or have custom code to calculate the center of mass.

Having to cycle through the whole creation can decrease the performance by a lot in my game as people can build anything they want with any size, there could be 5 to 50.000 parts in a single creation.

When the player is about to spawn their creation, the creation will always be anchored, if this would work with anchored assembly’s too, i could pre-calculate the center of mass even before spawning in.

If a player spawns their creation with an anchor block attached to it, the creation will always stay anchored so this cant even work as there is a possibility that the creation will always remain anchored.

This is an amazing feature which would make it extremely helpful to find each assembly, but if it doesn’t work correctly while its anchored, i cant make it work correctly in my game as there will always be situations where it just fails to work.

It’s not that “it doesn’t work correctly while its anchored”, this is just how assemblies work, and always have. If you want the center of mass of a set of anchored parts, you aren’t looking for the assembly’s center of mass, since there is more than one assembly.

There are anchor blocks people can place in my games which anchors their creation on a button press, if i have to calculate the center of mass while the creation is anchored

When I said “Why do you need to have all the parts anchored in the first place”, what I mean is you can make sure that individual parts in people’s creations are not anchored, and whenever they want them anchored, you simply weld to an anchored part at the assembly’s current center of mass.

The other option, if you want to find the center of mass of more than one assembly, is to write your own code. And it shouldn’t be as slow as it sounds, especially since you wouldn’t need to be recalculating it every frame. One idea that could work, is you could just cache the AssemblyCenterOfMass value from when all the parts were unanchored, and then just always use that value as certain parts become anchored. I’m sure there are other methods to efficiently maintain a set of parts and it’s center of mass.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.