Walking Underwater

I’m relatively new at scripting but for my game I am trying to make the player be able to transition from swimming into walking on the floor of the sea (baseplate) at the bottom of the water terrain. I can’t figure out how to do this and I’ve looked this topic up in the forum but I didn’t see any topics about this or similar. Any tips on achieving this?

2 Likes

You can disable the Humanoid Swimming state.

1 Like

In addition, you need to increase the density of the HumanoidRootPart. The most performant solution is to just change its material to a material like Enum.Material.Metal.

@SubtotalAnt8185
@Project_Aurora
Yeah but how would I allow the player to go back up if I disable swimming

I guess you could try to make it so that when the player presses the space bar using UserInputService it detects if the humanoid state is currently PlatformStanding and then changes the state of the humanoid back to swimming?

Depending on how you want this to work, the simplest way would be to raycast and check if they are touching the floor while swimming, disable the swim state so they begin walking under water, and listen in on the humanoid entering the Jumping state to cause them to swim again.

You can have your own state system above the humanoid state system. In your own state system have a toggle/flag for if the user wants to walk or swim, then give them a way to toggle it on or off. For example they could change this flag through a button on their keyboard or an in-game action(for example touching the ground or jumping). Then you just need to detect changes to the flag and replicate them accordingly to the humanoid state system below.

--if Humanoid.Jump then ?
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, true)
Torso.Material = Enum.Material.Plastic