i’m trying to make my model float like it’s in space kind of way but the model keeps falling down to the ground. it’s easy to do this with bodyforce but that’s deprecated and i want to do it the proper way using vectorforce.
local spiky = script.Parent
local gravity = workspace.Gravity
local att = spiky.cube.Attachment
local total_mass = 0
local vf = spiky.VectorForce
local DENSITY = 0.3
local FRICTION = 0.1
local ELASTICITY = 1
local FRICTION_WEIGHT = 1
local ELASTICITY_WEIGHT = 1
--get total mass
for _, part in pairs(spiky:GetChildren()) do
if part:IsA("BasePart") then
local customprops = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT)
local success, err = pcall(function()
part.CustomPhysicalProperties = customprops
end)
if success then
print("works")
else
print("error")
end
total_mass += part.AssemblyMass
end
end
vf.Force = Vector3.new(0, total_mass * gravity, 0)
vf.ApplyAtCenterOfMass = true
vf.RelativeTo = Enum.ActuatorRelativeTo.World
hey vamp, thanks for ur help man!!
yes. i added vectorforce and an attachment to each part in my model and set its relative to attachment0 and this is what im getting rn:
local att = Instance.new("Attachment", part)
local vf = Instance.new("VectorForce", part)
vf.Attachment0 = att
vf.Force = Vector3.new(0, gravity * part:GetMass(), 0)
vf.ApplyAtCenterOfMass = true
vf.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
local spiky = script.Parent
local gravity = workspace.Gravity
local att = spiky.cube.Attachment
local total_mass = 0
local vf = spiky.VectorForce
local DENSITY = 0.3
local FRICTION = 0.1
local ELASTICITY = 1
local FRICTION_WEIGHT = 1
local ELASTICITY_WEIGHT = 1
--get total mass
for _, part in pairs(spiky:GetChildren()) do
if part:IsA("BasePart") then
local customprops = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT)
local success, err = pcall(function()
part.CustomPhysicalProperties = customprops
end)
if success then
print("works")
else
print("error")
end
total_mass += part.AssemblyMass
end
end
vf.Attachment0 = att
vf.Force = Vector3.new(0, total_mass * gravity, 0)
vf.ApplyAtCenterOfMass = true
vf.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
add an attachment and vectorforce to the primary part.
assign the attachment to the vector force attachment0, applyatcenterofmass to true and change the relativeto properties to world.
note: u use a primary part so that you can use part.AssemblyMass. roblox calculates the total mass of your model so it saves you a few lines of code. :GetMass() will only get the mass of one part, not the mass of the whole model.
code:
-- zero gravity for a model
local spiky = script.Parent --model
local gravity = workspace.Gravity
local vf = spiky.PrimaryPart.VectorForce
local att = spiky.PrimaryPart.Attachment
local totalForce = Vector3.new(0, gravity * spiky.PrimaryPart.AssemblyMass, 0)
vf.Force = totalForce
vf.ApplyAtCenterOfMass = true
vf.Attachment0 = att
vf.RelativeTo = Enum.ActuatorRelativeTo.World
print({"VectorForce applied: "..tostring(vf.Force),
"AssemblyMass: "..spiky.PrimaryPart.AssemblyMass
})