Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I can't figure out how to make bobble effect more intense?

Asked by 3 years ago

So I made this sprint script that sets the humanoid walk speed to 32, I want to learn how to change the intensity of the bobble in the bobble script when the humanoid walk speed is set to 32. I've tried making bool variables to change the bobble intensity at certain times with no luck. Can you please explain to me what I have to do? Note that these are all local scripts.

bobble script in StarterCharacterScripts

local runService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

runService.RenderStepped:Connect(function()
    local time = tick()
    if humanoid.MoveDirection.Magnitude > 0 then
        local velocity = humanoid.RootPart.Velocity
        local x = math.cos(time * 9) / 2.5 -- change the last number to make less/more intense
        local y  = math.abs(math.sin(time * 12)) / 2.5 -- change the last number to make less/more intense

        local bobble = Vector3.new(x, y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
        humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)
    else
        humanoid.CameraOffset = humanoid.CameraOffset * 0.75
    end
end)

sprint script in StarterPlayerScripts

local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")

local function keyPress(inputObject, gameProcessed)
    if inputObject.UserInputType == Enum.UserInputType.Keyboard and gameProcessed == false then
        local keyValue = inputObject.KeyCode.Value
        local keyName = userInputService:GetStringForKeyCode(keyValue)

        if keyValue == 304 then
            if inputObject.UserInputState == Enum.UserInputState.Begin then
                players.LocalPlayer.Character.Humanoid.WalkSpeed = 64
            elseif inputObject.UserInputState == Enum.UserInputState.End then
                players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
            end
        end
    end
end

userInputService.InputBegan:Connect(keyPress)
userInputService.InputEnded:Connect(keyPress)

Answer this question