Changing Terrain water controlls

is there a script that spawns in when u play test for the behavior in terrain water? If yes, then where ??? I want to tweek it around a bit

Might be in the PlayerModule? (PlayerScripts)

What do you mean? What are you trying to tweak?

Thought so aswell, but the nearest I could find about Terrain Water is a line that states when the player enters terrain water, they‘ll enter the swimable state. Again, how does the game know what a swimmable state is without a module script? It has to be somewhere…but where?

When the player is idle inside terrain water, they swim up. I want the player to stay on one spot when they‘re in idle mode, that‘s what I need to tweek around

The swimable state refers to a HumanoidState, which is internally coded. Can’t view that. Try setting the state manually using Humanoid’s API and check the results.

Can you explain what Humanoid API is? Can I change the water Physics with it?

https://create.roblox.com/docs/reference/engine/classes/Humanoid

That is part of Humanoid physics, and since Humanoids are an engine feature, there is no Lua script for you to edit.

However, you may be able to use a script to constantly move the player back to where they stopped moving in order to stop them swimming up automatically:

-- What position the character should try to stay in without any input (idling)
local KeepPosition = Vector3.zero
-- What inputs the player was giving, used to determine when we should try and stop the character from moving
local LastMoveDirection = Vector3.zero

-- .Heartbeat runs every frame
RunService.Heartbeat:Connect(function()
	if Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
		-- Mostly self-explanatory, the extra Vector3.yAxis part is there in order to allow players to swim up by pressing the jump button (space)
		local MoveDirection = Humanoid.MoveDirection + Vector3.yAxis * (if UserInputService:IsKeyDown(Enum.KeyCode.Space) then 1 else 0)
		
		-- == 0 means there are no inputs
		if MoveDirection.Magnitude == 0 then
			
			-- Have we only just started idling?
			if LastMoveDirection ~= Vector3.zero then
				LastMoveDirection = Vector3.zero
				
				-- Maintain this position
				KeepPosition = RootPart.Position
			end
			
			-- Counteract the upwards velocity the Humanoid puts on the character to make it swim up
			RootPart.AssemblyLinearVelocity = KeepPosition - RootPart.Position
		else
			LastMoveDirection = MoveDirection
		end
	end
end)

Edit: This should be a LocalScript in StarterCharacterScripts for anyone who wants to test this out. Please note, this is not the full script and some variables have not been defined so that you have to do some parts yourself instead of CTRL+C CTRL+V.

That page does not describe how to implement the feature OP wants, please read the full post before replying!

ty very much. would that be a module or local script? In startercharacterscripts or workspace?

Oh, sorry, it should be a LocalScript (or a Script with RunContext set to Client) inside StarterCharacterScripts.

ok I’ll try it out right now :))

Please note, this is not the full script and some variables have not been defined so that you have to do some parts yourself instead of CTRL+C CTRL+V, because of the rules of #help-and-feedback:scripting-support, but generally this is usually how people (aka I) share scripts here :slight_smile:

Yes

yep I just noticed lol. I will change it up after school, just 1.5 hours left. Do you mean hrp by RootPart?

It works perfectly for pc, however when I go over to test it in mobile mode, and press the jump button, I swim up very very slowly until I eventually am pulled down to the same I started swiming up. That’s the working script

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local UserInputService = game:GetService("UserInputService")



local KeepPosition = Vector3.zero
-- What inputs the player was giving, used to determine when we should try and stop the character from moving
local LastMoveDirection = Vector3.zero

-- .Heartbeat runs every frame
RunService.Heartbeat:Connect(function()
	if Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
		-- Mostly self-explanatory, the extra Vector3.yAxis part is there in order to allow players to swim up by pressing the jump button (space)
		local MoveDirection = Humanoid.MoveDirection + Vector3.yAxis * (if UserInputService:IsKeyDown(Enum.KeyCode.Space) then 1 else 0)

		-- == 0 means there are no inputs
		if MoveDirection.Magnitude == 0 then

			-- Have we only just started idling?
			if LastMoveDirection ~= Vector3.zero then
				LastMoveDirection = Vector3.zero

				-- Maintain this position
				KeepPosition = RootPart.Position
			end

			-- Counteract the upwards velocity the Humanoid puts on the character to make it swim up
			RootPart.AssemblyLinearVelocity = KeepPosition - RootPart.Position
		else
			LastMoveDirection = MoveDirection
		end
	end
end)

Sorry kind of unnecessery comment but, could you pls respond?

Edit: I found a way simpler solution, just change the players hrp density to 1.77 in a script in ServerScriptService and it should work flawlessly for all devices

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.