Hello, DevForum Members! I am incorporating a particular bobble script in my game however the current one that I have makes the characters camera bounce from the left to the right when they move. How would I be able to alter this so that it only moves up and down, but not aggressively.
local RunService = game:GetService("RunService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
function UpdateBobbleEffect()
local CurrentTime = tick()
if Humanoid.MoveDirection.Magnitude > 0 then
local BobbleX = math.cos(CurrentTime * 10) * .25
local BobbleY = math.abs(math.sin(CurrentTime * 10)) * .25
local Bobble = Vector3.new(BobbleX, BobbleY, 0)
Humanoid.CameraOffset = Humanoid.CameraOffset:lerp(Bobble, .25)
else
Humanoid.CameraOffset = Humanoid.CameraOffset * .75
end
end
RunService.RenderStepped:Connect(UpdateBobbleEffect)
If you want it so your camera only bobbles up and down, you need to get rid of the “BobbleX” variable, as that is horizontal bobble. This is non tested, but will probably work:
local RunService = game:GetService("RunService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local BobblePower = 0.10
function UpdateBobbleEffect()
local CurrentTime = tick()
if Humanoid.MoveDirection.Magnitude > 0 then
local BobbleY = math.abs(math.sin(CurrentTime * 10)) * BobblePower
local Bobble = Vector3.new(Humanoid.CameraOffset.X, BobbleY, 0)
Humanoid.CameraOffset = Humanoid.CameraOffset:lerp(Bobble, .25)
else
Humanoid.CameraOffset = Humanoid.CameraOffset * .75
end
end
RunService.RenderStepped:Connect(UpdateBobbleEffect)
Basically this only replaces the Y Axis, and you can change the intensity by putting BobblePower lower.
I went through and tested the script and it works just as I was looking for! Thank you very much for replying to my post with this information, it will really help in building my game up.