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

Problems with my anti-gravity script - ship is sinking slowly?

Asked by
Taien 0
6 years ago

I'm trying to make a Space game. I want there to be gravity but I want the spaceships to float. I scoured this site and Google for some suggestions for code and found this tidbit:

function GetMassOfModel(model)
    local mass = 0
    for i, v in pairs(model:GetChildren()) do
        if v:IsA('BasePart') or v:IsA('Union') then
            mass = mass + v:GetMass()
        end
    end
    return mass
end

script.Parent.BodyForce.force = Vector3.new(0, game.Workspace.Gravity, 0) * GetMassOfModel(script.Parent.Parent)

The problem I'm having is that this doesn't totally negate the gravity. Very slowly, the ship starts to sink and then accelerates. Am I missing a part type that can weigh something? The ship has a VehicleSeat, and several sub-models. Are the sub-models possibly not being counted? I assumed GetChildren() got all children of that object, including those farther down the tree (children of children, etc). Am I wrong about that?

0
Can anyone please help with this? As a last resort I could just turn off gravity in the main flying Place and use separate Places for walking around the space stations, where gravity does exist...but I'd like to avoid that if possible. Taien 0 — 6y
0
I too am searching for help on this for a similar space station model. I want my players to be able to walk around so can't set game gravity to 0, but want the ship to float and eventually rotate realistically Karl_Poppa 11 — 4y

Answer this question