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

I'm trying to make a shouldercamera?

Asked by 10 years ago
wait (1)
cam = game.Workspace.CurrentCamera
char = script.Parent.Parent.Character
cam.CameraSubject = char:FindFirstChild("Right Arm")
cam.CameraType = "Follow"

game.Players.LocalPlayer.CameraMaxZoomDistance = [[20]]
game.Players.LocalPlayer.CameraMinZoomDistance = [[19]]

So Everything is working correctly, except The CameraZoomdistance properties aren't working, the player can still zoom in and out using I and O What am I doing wrong?

0
Please edit your post to use the "Lua" formatting button. That way, we can then read your code a bit easier. RoboFrog 400 — 10y
0
Ok, there you go. wantedfunnybunny2 20 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

instead of using CameraMaxZoomDistance = [[20]] you should use CameraMaxZoomDistance = 20, see if that works.

Ad
Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
10 years ago

I've answered this question many times.

                                                                                                                                                                                                                wait(1)
ALLOW_TOGGLE = true    -- true/false Allows the shoulder camera to be toggled using the key binded below.
TOGGLE_KEY = "p"       -- If ALLOW_TOGGLE is true, this key is used to toggle the shoulder camera. Also you can change it to right click if you you want to, or change it to other hot keys.
DEFAULT_ENABLED = true -- true/false. The default enabled state of the shoulder camera. Forced to true if toggling isn't allowed.
SMOOTH_ROTATION = true -- true/false. Makes your torso turn smoothly instead of sharply. Note that it puts a Body Gyro into the Torso.

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

player = game.Players.LocalPlayer
mouse = player:GetMouse()
enabled = DEFAULT_ENABLED
c = workspace.CurrentCamera
mirror = {}
h = nil
userInput = game:GetService("UserInputService")
isMobile = false

function createModel()
    local m = Instance.new("Model",c)
    m.Name = "ViewModel"
    local hack = Instance.new("Part",m)
    hack.Name = "HumanoidRootPart"
    hack.Transparency = 1
    hack.CanCollide = false
    hack.Anchored = true
    hack.CFrame = CFrame.new()
    local h = Instance.new("Humanoid",m)
    h.Sit = true
    h.Changed:connect(function ()
        h.Sit = true
    end)
    return m
end

function registerPart(v)
    local function mirrorPart(p,t)
        local m = p:clone()
        m.CanCollide = false
        m.Parent = model
        m.Transparency = (t or 0)
        local w = Instance.new("Weld",m)
        w.Part0 = p
        w.Part1 = m
        mirror[v] = m
        if m.Name == "Head" then
            m.Name = "H"
        end
        v.Changed:connect(function (property)
            local blist = {Position = true, CFrame = true, Parent = true, CanCollide = true}
            if not blist[property] then
                pcall(function () -- Some properties can't be queried :P
                    m[property] = v[property]
                end)
            end
        end)
        v.ChildAdded:connect(function (ch)
            ch.Archivable = true
            local cl = ch:clone()
            cl.Parent = m
            mirror[ch] = cl
        end)
        v.ChildRemoved:connect(function (ch)
            if mirror[ch] then
                mirror[ch]:Destroy()
                mirror[ch] = nil
            end
        end)
        m.Changed:connect(function ()
            m.CanCollide = false
        end)
    end
    if v:IsA("BasePart") and not mirror[v] and v.Name ~= "HumanoidRootPart" then
        mirrorPart(v)
    elseif v:IsA("Hat") then
        local h = v:WaitForChild("Handle")
        mirrorPart(h)
    elseif v:IsA("Clothing") or v:IsA("CharacterAppearance") then
        v:clone().Parent = model
    end
end

function updateCam()
    if h then
        if enabled then
            if model then
                local range = model:GetExtentsSize().Y/2
                local y = c.CoordinateFrame.lookVector.Y
                h.CameraOffset = Vector3.new(math.max(1.5,1.5-y),math.abs(y/2)-y*3.8642337322235,4-math.abs(y))
            else
                h.CameraOffset = Vector3.new(1.5,0.5,4)
            end
        else
            h.CameraOffset = Vector3.new()
        end
    end
end

function newCharacter(char)
    if not char then return end
    mirror = {}
    for _,v in pairs(c:GetChildren()) do
        if v.Name == "ViewModel" then
            v:Destroy()
        end
    end
    if not enabled then return end
    model = createModel()
    for _,o in pairs(char:GetChildren()) do
        registerPart(o)
    end
    char.ChildAdded:connect(registerPart)
    h = nil
    while not h do
        -- Why am I doing it like this? Well, in case you're me and you're re-naming 
        -- your humanoids, its nicer to not change the name of everything.
        for _,v in pairs(char:GetChildren()) do
            if v:IsA("Humanoid") then
                h = v
                break
            end
        end
        wait()
    end
    updateCam()
    player.CameraMaxZoomDistance = 0.5
    h.Died:connect(function ()
        if model then
            model:Destroy()
        end
    end)
    local t = char:WaitForChild("Torso")
    for _,v in pairs(t:GetChildren()) do
        if v.Name == "ShoulderCamGyro" then
            v:Destroy()
        end
    end
    if SMOOTH_ROTATION and enabled and mouse then
        local dir = c.CoordinateFrame.lookVector * Vector3.new(1,0,1)
        local b = Instance.new("BodyGyro",t)
        b.Name = "ShoulderCamGyro"
        b.maxTorque = Vector3.new(999999,999999,999999)
        b.cframe = CFrame.new(t.Position,t.Position+(c.CoordinateFrame.lookVector*Vector3.new(1,0,1)))
        b.D = 100
        game:GetService("RunService").RenderStepped:connect(function ()
            if h then
                h.AutoRotate = not enabled
            end
            if b and t then
                local dir = c.CoordinateFrame.lookVector * Vector3.new(1,0,1)
                b.cframe = CFrame.new(t.Position,t.Position+dir)
            end
        end)
    end
end

if mouse and ALLOW_TOGGLE and #TOGGLE_KEY == 1 and type(TOGGLE_KEY) == "string" then
    mouse.KeyDown:connect(function (key)
        if string.lower(key) == TOGGLE_KEY then
            enabled = not enabled
            if model then
                model:Destroy()
                newCharacter(player.Character)
                updateCam()
            end
        end
    end)
    mouse.Move:connect(updateCam)
end

if player.Character then
    newCharacter(player.Character)
end

local con do
    con = game:GetService("RunService").RenderStepped:connect(function ()
        isMobile = userInput.TouchEnabled
        if isMobile then
            con:disconnect()
            SMOOTH_ROTATION = false -- You can also Switch this to TRUE
            newCharacter(player.Character)
        end
    end)
end

0
Its better if you did it this way. (BY THE WAY, PUT THE SCRIPT IN LOCALSCRIPT) woodengop 1134 — 10y

Answer this question