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

Is it possible to make a player float?

Asked by
Hero_ic 502 Moderation Voter
9 years ago

I think its possible its just I don't understand how it works.

What I'm trying to do is make a game where the player can fly and I want the player to float when doing nothing but I dunno how to do this.

Thanks, KiHeros

1 answer

Log in to vote
1
Answered by 9 years ago

We can't make a script for you so I'll teach you how to make a part float: Roblox has gravity, the Gravitational pull is 96.2 studs per second squared. Which means you can set the gravity by 0 by making a body force push up 96.2 on the y axis per part.

--Inside a part:
local bf = Instance.new("BodyForce", script.Parent)
bf.force = Vector3.new(0,96.2,0) * script.Parent:GetMass() --Part floats

Using this knowledge we can make the part slowly fall to the ground by changing 96.2 to a smaller number like 48.1 which would make you get affected by half of ROBLOX's gravity:

--Inside a part:
local bf = Instance.new("BodyForce", script.Parent)
bf.force = Vector3.new(0,48.1,0) * script.Parent:GetMass() --Part floats

The problem with no gravity is if a player is using this and they jump, they will always go up until there is a force that acts upon it, like another player or a part. So make sure they don't go flying everywhere and end up in space.


Get the mass of a player

GetMass only works on one part, but the player's character has multiple parts, well according to my calculations the character without hats has a mass of 14. But we need to see how much the hat weights:

local character = script.Parent --Find the character
groups = {["Model"] = true, ["Hat"] = true} --Dictionary; add more here.
local mass = 0

function search(instance)
    for _,obj in pairs(instance:GetChildren()) do
        if groups[obj.ClassName] then
            search(obj)
        elseif obj:IsA("BasePart") then
            mass = mass+obj:GetMass()
        end
    end
end

search(character)


Hope it helps!

Ad

Answer this question