Trying to make model float with vector force

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

image

1 Like

Did you set the Attachment to the VectorForce’s Attachemt0?

1 Like

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
1 Like

i mean try this:

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
1 Like

i tried this rn and its like shooting up to the sky.

i tried 2 ways but your way; the relative to attachment0 is giving me more promising results. the force is just too great on the Y axis or sum.

ok so i found a solution. in order to make a whole model zero gravity you have to do this:

  1. assign a primary part to the model.
  2. add an attachment and vectorforce to the primary part.
    image
  3. assign the attachment to the vector force attachment0, applyatcenterofmass to true and change the relativeto properties to world.
    image
    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
})
1 Like

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