Recently I’ve switched from BodyForce to VectorForce, however I’m having some issues.
local force = Instance.new("VectorForce", projectile)
local mass = 0
for i,v in pairs (projectile:GetChildren()) do
if v:IsA("Part") or v:IsA("WedgePart") then
mass = mass + v:GetMass()
print(v.Name)
end
end
force.ApplyAtCenterOfMass = true
force.RelativeTo = "World"
force.Force = Vector3.new(0, mass*workspace.Gravity, 0)
force.Enabled = true
Why isn’t this code working? Could it be because the part I’m trying to apply it on is in a model?
You did not specify VectorForce.Attachment0 which every VF requires. Just create an attachment under the projectile and set the property to that. Also you can just use BasePart.AssemblyMass to get the mass of the model instead of looping through it’s children.
-- Avoid using the second argument of Instance.new (https://devforum.roblox.com/t/psa-dont-use-instancenew-with-parent-argument/30296)
local force = Instance.new("VectorForce")
local attachment = Instance.new("Attachment")
force.ApplyAtCenterOfMass = true
force.RelativeTo = "World"
force.Force = Vector3.new(0, projectile.AssemblyMass * workspace.Gravity, 0)
force.Attachment0 = attachment
force.Enabled = true
attachment.Parent = projectile
force.Parent = projectile