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

How to make BodyVelocity stop parts from floating?

Asked by 5 years ago

So I'm currently trying to make a fly script, whenever someone presses a letter they will (automatically) go up, instead of a slow levitation. But I want to know how can I stop BodyVelocity from floating me up? Is there a way that I can make it where my character just goes up in the air, doesn't move. Whenever a key is pressed W A S D Space and CTRL they will change positions and go up and down? I'm not sure if using BodyVelocity is the right way to make a fly but how do I stop the levitation? My code is

game:GetService("UserInputService").InputBegan:Connect(function(KeyDown, gameProcessed)
    if not gameProcessed then
        if KeyDown.KeyCode == Enum.KeyCode.E then
            local bv = Instance.new("BodyVelocity", game.Players.LocalPlayer.Character.HumanoidRootPart)
            bv.Velocity = Vector3.new(0, 5, 0)
            bv.Velocity = Vector3.new(4000, 4000, 4000)
        end
    end
end)
0
BodyVelocity will automatically force your velocity to be some given number (well, vector3). If you wish to counteract gravity, use bodyforce instead, add and subtract to determine how the player should move. Alternatively, you could use bodvelocity for movement while setting gravity to 0 locally. saenae 318 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

If you're just trying to make the player float when he presses a button then I suppose this could help: https://scriptinghelpers.org/questions/19753/how-do-i-make-my-character-float

Also if you want to stop the force you can do it by either two ways, deleting the bodyforce that's countering gravity, or anchoring the player's Head, then making the force go in reverse. This code makes it where when the player jumps, it's creates a force of 196.2 * the mass of all of it's parts which counteracts roblox's gravity and causes the player to float:

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
for _, v in pairs(character:GetChildren()) do
    if v:IsA("BasePart") then
        local mass = v:GetMass()
        local force = Instance.new("BodyForce")
        force.Name = 'float';
        force.force = mass * Vector3.new(0, 196.2, 0)
        force.Parent = v
    end
end
0
So all in total, BodyVelocity and BodyForce is the way to make a fly? Also, I will try this out. Bodymovers are new to me but I do know that they are used for Flying. So Velocity and Force right? User#21998 0 — 5y
0
To put it simply, yes. KardashevScale 110 — 5y
0
Alright so I took that guy's advice above of changing Gravity to 0 and then using Velocity to manage the height, then use bodyforce to manage movement. But how do I change the speed? You know, how do I stop the falling animation when im in the air while gravity is set to 0. I'm just really confused User#21998 0 — 5y
Ad

Answer this question