Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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?

0
Have you tried using the pairs() function to go through all its descendants to unanchor all BaseParts? UgOsMiLy 1074 — 6y
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. WackyTacky432 -5 — 6y

4 answers

Log in to vote
0
Answered by 6 years ago

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

Ad
Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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.

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

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. WackyTacky432 -5 — 6y
Log in to vote
0
Answered by 6 years ago

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

Answer this question