Greetings developers! I have recently decided to start a project involving fishing, however, I have come across a problem.
I am currently trying to achieve a swimming system like minecraft’s swimming system, where you can float and if you press Ctrl you can swim with custom animations. (Quick note: I am not using Roblox’s Water, I am using a part that represents the water.)
I have tried scripting on my own, it did not work, so I began searching though the forums, and the only good system that I was able to find was this one, and it would be a perfect fit, unfortunately, the creator has been terminated including his creations.
Nope, couldn’t figure it out, I used VectorForce instead of LinearVelocity, and the character kept flying away when i tried to do so.
(edit)
Here’s my current code:
local runService = game:GetService("RunService")
local waterFolder = workspace.WaterInstances
local plr = game.Players.LocalPlayer
local char = plr.Character
local swimming = false
repeat
task.wait(.1)
until plr and char
char.PrimaryPart = char:FindFirstChild("HumanoidRootPart")
local function checkWater()
for i, v in pairs(workspace:GetPartsInPart(char.PrimaryPart)) do
if v.Parent == waterFolder then
return true, v
end
end
return false, nil
end
runService.Heartbeat:Connect(function()
local check, water = checkWater()
if check == true then
swimming = true
-- print(check, water)
end
if swimming == true then
if not char.PrimaryPart:FindFirstChild("VectorForce") then
local attach = Instance.new("Attachment")
attach.Parent = char.PrimaryPart
local vectorForce = Instance.new("VectorForce")
vectorForce.Attachment0 = attach
vectorForce.Parent = char.PrimaryPart
end
--Character Keeps flying away when facing the camera
char.PrimaryPart.CFrame *= CFrame.lookAt(workspace.Camera.CFrame.Position, char.PrimaryPart.Position)
end
end)