I’m currently having an issue in my game where players will randomly float to the top of water and it makes playing the game super hard. Is there anyway to prevent players from automatically floating?
You can see whats happening in this game:
I’m currently having an issue in my game where players will randomly float to the top of water and it makes playing the game super hard. Is there anyway to prevent players from automatically floating?
You can see whats happening in this game:
Have you tried increasing the density of all parts in the player’s Character? Changing it to 1 makes the character neither float nor sink I believe, and > 1 makes the character sink.
How would I go about doing this?
I tested this, it should work:
local Players = game:GetService("Players")
local HeavyProps = PhysicalProperties.new(
1, -- density
0.3, -- friction
0.5 -- elasticity
)
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _,part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CustomPhysicalProperties = HeavyProps
end
end
end)
end)
Thank you!
It works on PC and my phone, but seems to break for this person and others. I wonder if it has to do with packages
https://gyazo.com/03ab14f95e8386c04650fe22ea0a6f96
I just tested it again with a custom package, try connecting to plr.CharacterAppearanceLoaded
instead of plr.CharacterAdded
.
Thank you so much!! I’ll test it right now
Edit: Worked perfectly. You’re awesome man
Woah, thank you so much
Just a forewarning that CharacterAppearanceLoaded will not fire for blank characters. I believe this was sent patched but instances like StarterPlayer.LoadCharacterAppearance as false may give you that trouble.
I personally like CharacterAdded, though I believe that will be superseded in the future and only kept for compatibility and legacy reasons. In either case, I’d create a catcher function for these kinds of things.
local Players = game:GetService("Players")
local HeavyProperties = PhysicalProperties.new(
1, -- density
0.3, -- friction
0.5 -- elasticity
)
local function configurePhysicalProperties(Part)
if Part:IsA("BasePart") then
Part.CustomPhysicalProperties = HeavyProperties
end
end
Players.PlayerAdded:Connect(function (Player)
Player.CharacterAdded:Connect(function (Character)
Character.DescendantAdded:Connect(configurePhysicalProperties)
for _, Part in pairs(Character:GetDescendants()) do
configurePhysicalProperties(Part)
end
end)
end)
My only qualm here is that it’s typically better to do this as in when the character’s appearance loads and while this accounts for new parts added to a character, it also fires for every new descendant.
Catcher functions are definitely very useful if you manipulate the contents of an assembly, but sometimes they can be a little trouble. I don’t think this should be particularly expensive though.
Appreciate this, I edited it to use a script that floats your character when you drown instead of sinking them.