从第一人称切换到第三人称后玩家不可见

问题描述 投票:0回答:1

因此,游戏在介绍后会通过启用第一人称脚本将摄像机切换到第一人称:

开启第一人称的介绍脚本的一部分:

v.MouseButton1Click:Connect(function()
    script.Light:Play()
    imgout:Play()
    bout:Play()

    g.Visible = false
    gOL.Visible = true
    
    wait(1)
    grin:Play()
    
    
    --Function
    
    wait(2)
    local evt = script.Parent.Parent.Parent.FireMenu
    script.Parent.Parent.Parent.FireMenu.Value = false
    b.MainMenuHandler:Destroy()
    cuc.CameraType = Enum.CameraType.Custom
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
    b.Parent.Parent.Parent.Parent["Camera Bobble"].Enabled = true
    game.Players.LocalPlayer.Character.PrimaryPart.CFrame = workspace.SpawnRoomPlay.CFrame
    game.Players.LocalPlayer.Character.PrimaryPart.Anchored = false
    logo.Visible = false
    wait(2)
    grout:Play()
    grout.Completed:Once(function()
        b.Parent:Destroy()
    end)    
end)

这是“相机摆动”/第一人称脚本:

-- << Variables >> --

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Camera = game:GetService("Workspace").CurrentCamera
local UserInputService = game:GetService("UserInputService")
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local bobbing = nil
local func1 = 0
local func2 = 0
local func3 = 0
local func4 = 0
local val = 0
local val2 = 0
local int = 10
local int2 = 10
local vect3 = Vector3.new()

-- << Functions >> --

UserInputService.MouseIconEnabled = true

function lerp(a, b, c)
    return a + (b - a) * c
end


Humanoid.CameraOffset = Vector3.new(0,-0.1,-0.725)
Camera.FieldOfView = 90

bobbing = game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
    
    deltaTime = deltaTime * 60
    if Humanoid.Health <= 0 then
        bobbing:DisConnect()
        return
    end
    local rootMagnitude = Humanoid.RootPart and Vector3.new(Humanoid.RootPart.Velocity.X, 0, Humanoid.RootPart.Velocity.Z).Magnitude or 0
    local calcRootMagnitude = math.min(rootMagnitude, 50)
    if deltaTime > 3 then
        func1 = 0
        func2 = 0
    else
        func1 = lerp(func1, math.cos(tick() * 0.5 * math.random(10, 15)) * (math.random(5, 20) / 200) * deltaTime, 0.05 * deltaTime)
        func2 = lerp(func2, math.cos(tick() * 0.5 * math.random(5, 10)) * (math.random(2, 10) / 200) * deltaTime, 0.05 * deltaTime)
    end
    Camera.CFrame = Camera.CFrame * (CFrame.fromEulerAnglesXYZ(0, 0, math.rad(func3)) * CFrame.fromEulerAnglesXYZ(math.rad(func4 * deltaTime), math.rad(val * deltaTime), val2) * CFrame.Angles(0, 0, math.rad(func4 * deltaTime * (calcRootMagnitude / 5))) * CFrame.fromEulerAnglesXYZ(math.rad(func1), math.rad(func2), math.rad(func2 * 10)))
    val2 = math.clamp(lerp(val2, -Camera.CFrame:VectorToObjectSpace((Humanoid.RootPart and Humanoid.RootPart.Velocity or Vector3.new()) / math.max(Humanoid.WalkSpeed, 0.01)).X * 0.08, 0.1 * deltaTime), -0.35, 0.2)
    func3 = lerp(func3, math.clamp(UserInputService:GetMouseDelta().X, -5, 5), 0.25 * deltaTime)
    func4 = lerp(func4, math.sin(tick() * int) / 5 * math.min(1, int2 / 10), 0.25 * deltaTime)
    if rootMagnitude > 1 then
        val = lerp(val, math.cos(tick() * 0.5 * math.floor(int)) * (int / 200), 0.25 * deltaTime)
    else
        val = lerp(val, 0, 0.05 * deltaTime)
    end
    if rootMagnitude > 12 then
        int = 20
        int2 = 18
    elseif rootMagnitude > 0.1 then
        int = 12
        int2 = 14
    else
        int2 = 0
    end

    Player.CameraMaxZoomDistance = 0.5
    Player.CameraMinZoomDistance = 0.5
    vect3 = lerp(vect3, Camera.CFrame.LookVector, 0.125 * deltaTime)
end)

这部分脚本来自游戏的一部分,当触发接近提示时,它会禁用第一人称并启用自上而下视图/第三人称脚本并将玩家传送到外面:

ev_act.Triggered:Connect(function(plr)
    local char = plr.Character
    char.PrimaryPart.Anchored = true
    k.Parent.Visible = true
    fadein:Play()
    fadein.Completed:Connect(function()
        plr.CameraMode = Enum.CameraMode.Classic
        script3d.Enabled = true
        script1s.Enabled = false
        local sfx = script["Dumbwaiter 2 (SFX)"]
        local bell = script["Elevator Bell"]
        loading.Visible = true
        loading.TextLabel.Text = "waiting..."
        sfx:Play()
        sfx.Ended:Connect(function()
            char.PrimaryPart.CFrame = workspace.Outside.CFrame
            char.PrimaryPart.Anchored = false
            loading.TextLabel.Text = "done."
            bell:Play()
            wait(0.5)
            loading.Visible = false
            fadeout:Play()
            fadeout.Completed:Connect(function()
                k.Parent.Visible = false
            end)
        end)
    end)
end)

这是第三人称脚本:

local function updateCamera()
    local character = game.Players.LocalPlayer.Character
    if character then
        local rootPart = character:FindFirstChild("HumanoidRootPart")
        if rootPart then
            -- Calculate camera position
            local cameraPosition = rootPart.Position + Vector3.new(0, 10, 10)
            workspace.Camera.CFrame = CFrame.lookAt(cameraPosition,rootPart.Position)
            -- Set camera CFrame
            game.Workspace.CurrentCamera.CFrame = CFrame.new(cameraPosition, rootPart.Position)
        end
    end
end

game:GetService("RunService").RenderStepped:Connect(updateCamera)

这就是玩家被传送到外面并处于第三人称模式后发生的情况: Player cannot be seen

我希望玩家可见。

lua roblox luau roblox-studio
1个回答
0
投票

您是否尝试过将本地玩家的所有角色部分透明度设为0?

© www.soinside.com 2019 - 2024. All rights reserved.