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

View Bobbing Script stopped working with certain scripts?

Asked by
clrik 8
6 years ago
Edited 6 years ago

I need help, I am using this view bobbing script and I need help fixing it. I am making a short horror/puzzle game and I need some help with some of the scripts. . .

View Bobbing Script

repeat wait() until game.Players.LocalPlayer.Character

camera = game.Workspace.CurrentCamera
character = game.Players.LocalPlayer.Character

Z = 0

damping = character.Humanoid.WalkSpeed / 2

PI = 3.1415926

tick = PI / 2

running = false
strafing = false

character.Humanoid.Strafing:connect(function(bool)
    strafing = bool
end)

character.Humanoid.Jumping:connect(function()
    running = false
end)

character.Humanoid.Swimming:connect(function()
    running = false
end)

character.Humanoid.Running:connect(function(speed)
    if speed > 0.1 then
        running = true
    else
        running = false
    end
end)

function mix(par1, par2, factor)
    return par2 + (par1 - par2) * factor
end

while true do
    game:GetService("RunService").RenderStepped:wait()

    fps = (camera.CoordinateFrame.p - character.Head.Position).Magnitude

    if fps < 0.52 then
        Z = 1
    else
        Z = 0
    end

    if running == true and strafing == false then
        tick = tick + character.Humanoid.WalkSpeed / 92 --Calculate Bobbing speed.
    else
        if tick > 0 and tick < PI / 2 then
            tick = mix(tick, PI / 2, 0.9)
        end
        if tick > PI / 2 and tick < PI then
            tick = mix(tick, PI / 2, 0.9)
        end
        if tick > PI and tick < PI * 1.5 then
            tick = mix(tick, PI * 1.5, 0.9)
        end
        if tick > PI * 1.5 and tick < PI * 2 then
            tick = mix(tick, PI * 1.5, 0.9)
        end
    end

    if tick >= PI * 2 then
        tick = 0
    end 

    camera.CoordinateFrame = camera.CoordinateFrame * 
        CFrame.new(math.cos(tick) / damping, math.sin(tick * 2) / (damping * 2), Z) * 
        CFrame.Angles(0, 0, math.sin(tick - PI * 1.5) / (damping * 20)) --Set camera CFrame
end

It sadly doesn't work with these 2 scripts. . .

First Person Seat thing...

while wait(1) do
self = script.Parent
c = workspace.CurrentCamera

player = game.Players.LocalPlayer
char = player.Character or player.CharacterAdded:wait()
humanoid = char:WaitForChild("Humanoid")
function ok()
humanoid.CameraOffset = Vector3.new(0,0,-1.2)
end
function ok2()
humanoid.CameraOffset = Vector3.new(0,-1,-1.2)
end
function ok3()
humanoid.CameraOffset = Vector3.new(0,-3,-1.2)
end

-- Apply some properties

player.CameraMaxZoomDistance = 8
if humanoid.CameraOffset == Vector3.new(0,0,0) then
ok()
elseif humanoid.CameraOffset == Vector3.new(0,0,-1.2) then
ok()
elseif
humanoid.CameraOffset == Vector3.new(0,-1,-1.2) then
ok2()
elseif
humanoid.CameraOffset == Vector3.new(0,-3,-1.2) then
ok3()
end


function lock(part)
    if part and part:IsA("BasePart") then
        part.LocalTransparencyModifier = part.Transparency
        part.Changed:connect(function (property)
            part.LocalTransparencyModifier = part.Transparency
        end)
    end
end

for _,v in pairs(char:GetChildren()) do
    lock(v)
end

char.ChildAdded:connect(lock)

c.Changed:connect(function (property)
    if property == "CameraSubject" then
        if c.CameraSubject and c.CameraSubject:IsA("VehicleSeat") and humanoid then
            -- Vehicle seats try to change the camera subject to the seat itself. This isn't what we wan't really.
            c.CameraSubject = humanoid;
        end
    end
end)
end

and

First Person script (with crosshair and shows body, with smooth sensitivity).

repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")

CanToggleMouse = {allowed = true; activationkey = Enum.KeyCode.F;} -- lets you move your mouse around in firstperson
CanViewBody = false         -- whether you see your body
Sensitivity = 0.6       -- anything higher would make looking up and down harder; recommend anything between 0~1
Smoothness = 0.05       -- recommend anything between 0~1
FieldOfView = 90        -- fov

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local m = player:GetMouse()
m.Icon = "http://www.roblox.com/asset/?id=569021388" -- replaces mouse icon
local character = player.Character or player.CharacterAdded:wait()
local humanoidpart = character.HumanoidRootPart

local head = character:WaitForChild("Head")
local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p 
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0

local running = true
local freemouse = false

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

function updatechar()

    for _, v in pairs(character:GetChildren())do
        if CanViewBody then
            if v.Name == 'Head' then
                v.LocalTransparencyModifier = 1
                v.CanCollide = false
            end
        else
            if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
                v.LocalTransparencyModifier = 1
                v.CanCollide = false
            end
        end
        if v:IsA'Accessory' then
            v:FindFirstChild('Handle').LocalTransparencyModifier = 1
            v:FindFirstChild('Handle').CanCollide = false
        end
        if v:IsA'Hat' then
            v:FindFirstChild('Handle').LocalTransparencyModifier = 1
            v:FindFirstChild('Handle').CanCollide = false
        end

    end

end

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

input.InputChanged:connect(function(inputObject)

    if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
        local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness

        local X = TargetAngleX - delta.y 
        TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
        TargetAngleY = (TargetAngleY - delta.x) %360 
    end 

end)

input.InputBegan:connect(function(inputObject)

    if inputObject.UserInputType == Enum.UserInputType.Keyboard then
        if inputObject.KeyCode == CanToggleMouse.activationkey then
            if CanToggleMouse.allowed and freemouse == false then
                freemouse = true
            else
                freemouse = false
            end
        end
    end

end)

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 

runService.RenderStepped:connect(function()

    if running then
        updatechar()

        CamPos = CamPos + (TargetCamPos - CamPos) *0.28 
        AngleX = AngleX + (TargetAngleX - AngleX) *0.35 
        local dist = TargetAngleY - AngleY 
        dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist 
        AngleY = (AngleY + dist *0.35) %360
        cam.CameraType = Enum.CameraType.Scriptable

        cam.CoordinateFrame = CFrame.new(head.Position) 
        * CFrame.Angles(0,math.rad(AngleY),0) 
        * CFrame.Angles(math.rad(AngleX),0,0)
        * CFrame.new(0,0.5,0) -- offset

        humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
        else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
    end

    if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
        running = false
    else
        running = true
        if freemouse == true then
            game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
        else
            game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
        end
    end

    if not CanToggleMouse.allowed then
        freemouse = false
    end

    cam.FieldOfView = FieldOfView

end)

I am thinking that one of the scripts are not compatible with the View Bobbing. . .

Any help / adivce (adivce for to become a better scripter) Plz?

0
If you're just going to paste a slew of code of which I assume you don't understand how it works, then nobody will be able to help you. Do you expect me to read through all of that knowing what it does? T0XN 276 — 6y
0
What do you mean by "not compatible"? T0XN 276 — 6y
0
Ok, I'll label them, sorry jeez. Also what I mean by "not compatible" is that the 2 other scripts on the bottom are messing with my viewbobbing script (view bobbing like minecraft). clrik 8 — 6y
0
The scripts breaks because all three of them are referencing the camera, and each script is trying to use it in a different context. T0XN 276 — 6y
View all comments (2 more)
0
ok I understand. clrik 8 — 6y
0
can you add an answer? clrik 8 — 6y

3 answers

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

"accept this"

Ad
Log in to vote
0
Answered by
clrik 8
6 years ago
Edited 6 years ago

Just put a random answer and I'll accept it because I fixed the script.

Log in to vote
0
Answered by 6 years ago

ok here u go

Answer this question