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

How can I make people float in my water?

Asked by 9 years ago

I am making a Naval game and I am wondering how i can let characters float in the water so they do not just drop down to the bottom.

1 answer

Log in to vote
4
Answered by
Discern 1007 Moderation Voter
9 years ago

Try adding a BodyPosition to the player's Torso. Make it so the force is only applied on the Y Axis.

Make sure this is a LocalScript inside StarterPlayerScripts (inside StarterPlayer).

waterLevel = 0 --The Y coordinate for the water level at which you want the player to float
player = game.Players.LocalPlayer

while wait() do
    if player.Character then
        if player.Character:WaitForChild("Torso").Position.y <= waterLevel and not player.Character:WaitForChild("Torso"):findFirstChild("WaterFloatForce") then
            bp = Instance.new("BodyPosition", player.Character.Torso)
            bp.Name = "WaterFloatForce"
            bp.D = 500
            bp.P = 1000
            bp.maxForce = Vector3.new(0, 10000, 0)
            bp.position = Vector3.new(0, waterLevel, 0)
        elseif player.Character.Torso.Position.y > 0 and player.Character.Torso:findFirstChild("WaterFloatForce") then
            for i,v in pairs(player.Character.Torso:GetChildren()) do
                if v.Name == "WaterFloatForce" then
                    v:Destroy()
                end
            end
        end
    end
end
=

This script is tested and it works. Just make sure you change waterLevel to the Y Axis at which you want the player to float. For example, if you want your player to float when you the player is at a Vector3 of RANDOMXVALUE, 10, RANDOMZVALUE then you would change waterLevel to 10 since the Y Axis at which you want them to float at is 10.

If you would like to learn more about BodyPosition, check out this link and this link!

If I helped you, be sure to Accept my Answer! :D

0
Thanks! That really helped! iiJamesHardenXIII 0 — 9y
Ad

Answer this question