Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What script can I use to move a model with velocity in Roblox?

I have a model in the air that gets unanchored after a certain period of time and I want it to come straight down gradually with velocity, like a normal falling speed, but I don't know what to put for that in regards to a model. anyone know?

2 comments

0

Have you tried using the pairs() function to go through all its descendants to unanchor all BaseParts?

0

I don't really understand what you're saying, sorry. I just want to know if there is any way that a script can control the velocity and direction (down) of a falling model, that's what I hope anyway.

4 answers

Here is an example with BodyVelocities:


local  bv = script.Parent
bv.Velocity = Vector3.new(0,-100,0)

The -100 with make the velocity go down

Try this:

local model = script.Parent -- set this to what model you want to unanchor.

local baseparts = {}
for i,v in pairs(model:GetDescendants())do
	if v:IsA("BasePart")then
		v.Anchored = false
		table.insert(baseparts,v)
	end
end
for i,v in pairs(baseparts)do
	local weld = Instance.new("Weld")
	weld.C0 = baseparts[1].CFrame:inverse() * v.CFrame
	weld.Part0 = baseparts[1]
	weld.Part1 = v
	weld.Parent = model
end

That would make the anchored model unachored, while keeping the relative positions. If you want the model to fall at "normal speed" then this is what you'd do.

If you call a part in the model Base, you can try something like this in a script:

local model = script.Parent --set to model
local percentGravity = 50 --change to alter weightlessness

--weld the model together & unanchor:
for _,v in pairs(model:GetDescendants()) do
	if v:IsA("BasePart") then
		v.Anchored = false
		local w = Instance.new("Weld")
		w.Part0 = v
		w.Part1 = model.Base
		w.C1 = w.Part1.CFrame:toObjectSpace(w.Part0.CFrame)
		w.Parent = w.Part0
	end
end

--function to get mass of model:
function getMass(mod)
	local mass = 0
	for _,v in pairs(mod:GetDescendants()) do
		if v:IsA("BasePart") then
			mass = mass + v:GetMass()
		end
	end
	return mass
end

--add weightlessness to model:
local antigrav = Instance.new("BodyForce")
antigrav.Parent = model.Base
local mass = getMass(model)
antigrav.Force = Vector3.new(0,workspace.Gravity,0)*(mass*(percentGravity/100))

If you want it to fall normally, set percentGravity to 0.

1 comment

0

update: thanks man this script works, I called the part in the model Basepart instead of just base and that's why it wasn't working but it works now, thank you.

thanks everybody for your suggestions, thanks to mattscy for the script as this one works for me, just what i wanted.

This discussion is preserved as it was. New answers, comments, and votes are closed.