Okay, so, i’m working on making a swimming system for a shipping game i’m making, where there’s the ‘infinite water’ mesh things.
My idea for the swimming is that there will be a client side block that is spawned in, big enough to go past the players max zoom distance, and the block follows the player’s X and Z(forward backwards and left right) axis, so that when I jump in the water, or underneath the ‘infinite water’, i’ll jump into the block.
My next stage of the system is so that when you are inside/touching the transparent, noncancollide block, your player starts swimming like it’s water terrain.
I hope this makes sense as Im hoping someone could assist me in making the block follow the player around.
Why not script it to check if the player is below the water level, then make them swim. You wouldn’t need a ‘following block’.
Try the Search button up top because I’ve seen a few posts about scripted swimming before.
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
-- Creates the block.
local swimBlock = Instance.new("Part")
swimBlock.Size = Vector3.new(100, 100, 100) -- Adjust size if needed!
swimBlock.Anchored = true
swimBlock.CanCollide = false
swimBlock.Transparency = 1 -- Make it invisible or not, your choice.
swimBlock.Parent = workspace
-- Updates the block's position.
RunService.RenderStepped:Connect(function()
if rootPart then
local newPosition = Vector3.new(rootPart.Position.X, swimBlock.Position.Y, rootPart.Position.Z)
swimBlock.Position = newPosition
end
end)
-- Detects when the player touches the block!
swimBlock.Touched:Connect(function(hit)
if hit.Parent == character then
-- Trigger swimming behavior here
print("Player is swimming")
-- You could also add code here to change the player's movement to swimming mode.
end
end)
I believe something like this would be your starting point. But only the starting point. There would be alot more you could or would make.
I’ve added a message at line 26 which tells you that you would write in a few lines of code to trigger the swimming behavior. If you’re confused on how you would do that, just reply to this message back and I would be happy to help!
Side note: You can also add code at line 28 if you wanted to change the player’s movement to swimming mode.
You could make a startedSwimming function which is triggered when the player touches the invisible block, which adjusts the player’s speed, gravity, and animation to simulate swimming.
You could also make a stoppedSwimming function which is called when the player is no longer touching the block, resetting their speed, gravity, and stopping the swimming animation.
Along with that, you could use RunService.Stepped to check if the player is still touching the block and stops swimming if they aren’t. This would ensure that the player exits swimming mode as soon as they leave the water block.
And @yesssssssss90900
Again, why does the player need to be in a moving block if you could just check to see if the player is below a certain Y Position (say a stud below the water surface) to start the animation(s) for swimming?
It’d save the Touched event and moving the Part with the player.
For infinite water just make a 2048x2048 ‘water’ part, then put a BlockMesh in it with the scale set to 10000x10000 which would make the water appear to be 204800000 x204800000 studs.
Easy peasy lemon squeezy.