I want to make a bobble system for my first person horror game but I encountered an issue
When I walk, my body parts in my pov are shaking so much, but I don’t want them to shake, is there a solution to my problem ?
I tried manipulating the positions and more but couldn’t fix this problem
Also i use a script to show my body parts at first person
Here’s the script i use for the first camera and bobble
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local TimeMoving = 0
local Intensity = 0.5
local NormalSpeed = 16
local Distance = 1.3
local frequence = 1
local chosenLerpRateX
local chosenLerpRateY
--Bobble Parameters
local lerpPowerX = 0.25
local lerpPowerY = 0.40
local StartTreshold = 2
local TimeMoving = 0
local CurrentTime
--Reset camera function
local FirstPersonVector = Vector3.new(0, 0,-1.8)
local function SetCameraToFirstPerson(setting)
local speed = 0.1
if setting == "smooth" then
Humanoid.CameraOffset = Humanoid.CameraOffset:lerp(FirstPersonVector, speed)
else
Humanoid.CameraOffset = FirstPersonVector
end
end
SetCameraToFirstPerson()
function lerp(a, b, t)
return a + (b - a) * t
end
--Main loop
RunService.RenderStepped:Connect(function(step)
--FirstPerson (show body and zoom a little bit)
--Humanoid.CameraOffset = Vector3.new(0,0,-1)
for i, part in ipairs(Character:GetChildren()) do
if part.ClassName == "MeshPart" and part.Name ~= "Head" then
part.LocalTransparencyModifier = 0
end
end
--bobble thing :
if Humanoid.MoveDirection.Magnitude > 0 then
if CurrentTime == nil then return end
local Speed = Humanoid.RootPart.Velocity.Magnitude
local T = tick()
local DeltaTime = tick() - CurrentTime
TimeMoving = TimeMoving + DeltaTime
if TimeMoving < StartTreshold then
local StartWalkingLerp = 0.25 * TimeMoving
chosenLerpRateX = StartWalkingLerp
chosenLerpRateY = StartWalkingLerp
else
chosenLerpRateX = lerpPowerX
chosenLerpRateY = lerpPowerY
end
--print(chosenLerpRate)
-- Is the character walking?
local bobble_X = 0.3 * 0.5 * math.cos(2 * math.pi * frequence * T) * math.min(1, Speed / NormalSpeed)
local bobble_Y = 0.5 * 0.7 * math.abs(math.sin(2 * math.pi * frequence * T)) * math.min(1, Speed / NormalSpeed)
--print("Before : ",bobble_Y)
--print("After : ",bobble_Y)
--print("before : ",Humanoid.CameraOffset)
--local bobble = Vector3.new(bobble_X, bobble_Y, FirstPersonVector.Z)-- * math.min(1, velocity.Magnitude / Humanoid.WalkSpeed)
local currentOffset = Humanoid.CameraOffset
--bobble_X = lerp(currentOffset.X, bobble_X, chosenLerpRateX)
bobble_Y = lerp(currentOffset.Y, bobble_Y, chosenLerpRateY)
Humanoid.CameraOffset = Vector3.new(0, bobble_Y, FirstPersonVector.Z) --Replace with Tweens cuz it's bad
else
-- Scale down the CameraOffset so that it shifts back to its regular position.
TimeMoving = 0
SetCameraToFirstPerson("smooth")
end
CurrentTime = tick()
end)