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

How would I make a part free fall at a specified rate?

Asked by 8 years ago

I'm trying to add a a script that would make unanchored parts when released fall at a slower rate than normal, due to (in real life) air resistance.

0
Use a body mover (I recommend BodyForce) to add thrust upwards while canceling out a fraction of the gravity effects (More on this here ---> http://wiki.roblox.com/index.php?title=API:Class/BodyForce ) . Otherwise, if you want to cancel out the gravity completely and add a certain velocity to an axis, use BodyVelocity (More on that here -------> http://wiki.roblox.com/index.php?title=API:Class/Bod LateralLace 297 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Exactly what LateralLace said: Use a BodyForce to cancel out a fraction of the gravity effects

Put a BodyForce in your parts with the Y force set to a fraction of 196.2*mass

local gravity = 0.9; --Relative, 1 is normal gravity and 0 is none
local gd = function(i)
    local queue = {};
    local returns = {};
    local v = i;
    while v do
            local t = v:GetChildren();
            for i = 1, #t do
                    local v = t[i]
                    returns[#returns+1] = v;
                    queue[#queue+1] = v;
            end;
            v = queue[#queue];
            queue[#queue] = nil;
        end;
    return returns;
end;
gravity = 1-gravity; -- Shh shh
for k,v in next, gd(workspace) do
    if not d:IsA("BasePart") then return end;
    local ag = Instance.new("BodyForce");
    ag.Name = "AirResistanceHandle";
    ag.force = Vector3.new(0,196.2*v:GetMass()*gravity,0);
    ag.Parent = v;
end;
workspace.DescendantAdded:connect(function(d)
    if not d:IsA("BasePart") then return end;
    local ag = Instance.new("BodyForce");
    ag.Name = "AirResistanceHandle";
    ag.force = Vector3.new(0,196.2*d:GetMass()*gravity,0);
    ag.Parent = d;
end);
workspace.DescendantRemoving:connect(function(d)
    if d:FindFirstChild("AirResistanceHandle") then
        d.AirResistanceHandle:Destroy();
    end
end);

What's going on here?
First, I get all of the descendants in the workspace. The function used for that can be found in Valkyrie. Then, I add a bodyforce to them and set it to cancel out a fraction of gravity. I do the same to any new additions to the workspace. Then I destroy it if the part leaves the workspace because I'm far too lazy.

Resources:

Ad

Answer this question