In my game gravity is not constant everywhere, the player can go on the underside of planets and into space. I use a VectorForce in each object and calculate the direction and force of gravity every frame. This is not the most efficient method, it would be better to use a single VectorForce for each assembly
Currently there is no way to get existing assemblies or detect when ones are added or removed
--example
game:GetService("PhysicsService"):GetAssemblies(workspace.Model) --Get all assemblies connected/parented to workspace.Model
game:GetService("PhysicsService").AssemblyAdded:Connect(function(Assembly)
print(Assembly.RootPart, Assembly.Parts)
end)
game:GetService("PhysicsService").AssemblyRemoved:Connect(function() end)
It would be really helpful if you could go into more detail on your use case and the problems you are trying to solve. (see How to post a Feature Request).
From what you have described, you could only add VecorForces to Parts where (Part.AssemblyRootPart == Part), which should guarantee only 1 VectorForce per assembly.
It’s important to note that there is no “assembly instance” that could accessed in the way you are proposing. It’s simply a set of connected parts. Have you seen the latest physics API additions here?
Oh I didn’t see that, doesn’t look like they’re documented at all on the devhub. So if I wanted to get assemblies, would something like this work reliably? In my game assemblies can also be split so I need to be able to detect that too
local Assemblies = {}
for _, Child in pairs(workspace.Model:GetDescendants()) do
if (Child:IsA("BasePart")) then
local AssemblyRootPart= Child.AssemblyRootPart
if (not Assemblies[AssemblyRootPart]) then
Assemblies[AssemblyRootPart] = {}
end
table.insert(Assemblies[AssemblyRootPart], Child)
Child:GetPropertyChangedSignal("AssemblyRootPart"):Connect(function()
table.remove(Assemblies[AssemblyRootPart], table.find(Assemblies[AssemblyRootPart], Child))
AssemblyRootPart = Child.AssemblyRootPart
if (not Assemblies[AssemblyRootPart]) then
Assemblies[AssemblyRootPart] = {}
end
table.insert(Assemblies[AssemblyRootPart], Child)
end)
end
end