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

DevCameraOcclusionMode, Online vs Offline issues?

Asked by 9 years ago

The following code that I have keeps a small part under the player at all times. The camera also provides a 'birds-eye view' of the player and everything around the player. When I test it offline, everything seems to work perfectly.

This is a localscript under StarterGui. I have set the DevCameraOcclusionMode to Invisicam through StarterPlayer and the Max and MinZoom property are both at 400.

It seems to only have this issue because the camera is of type scriptable.

Visual Examples:

Offline

Online


local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()

local root = chr:WaitForChild("HumanoidRootPart")
local leftLeg = chr:WaitForChild("Left Leg")
local rightLeg = chr:WaitForChild("Right Leg")
local hum = chr:FindFirstChild("Humanoid")


local camera = workspace.CurrentCamera
camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable;
camera.CameraSubject = plr;


local part = Instance.new("Part",workspace)
part.CanCollide = false;
part.Anchored = true;
part.FormFactor = Enum.FormFactor.Custom
part.Size = Vector3.new(7,.1,6)
part.Transparency = 1;
local gui = Instance.new("SurfaceGui",part)
gui.Face = "Top"
local decal = Instance.new("ImageLabel",gui)
decal.Size = UDim2.new(1,60,.8,0)
decal.Position = UDim2.new(.1,-20,.2,-15)
decal.Image = "http://www.roblox.com/asset/?id=276509139"
decal.BackgroundTransparency = 1;
local falling = false;

local mouse = plr:GetMouse()
mouse.TargetFilter = workspace.Map

function getBase(side)
    local sign = (side == "up" and 1 or -1);
    local ray = Ray.new(root.Position, Vector3.new(0, 1000 * sign, 0))
    local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {chr,part,camera})
    return hit,position;
end

--[[
hum.Died:connect(function()
    part:Destroy()
    chr = plr.CharacterAdded:wait()
    root = chr:WaitForChild("HumanoidRootPart")
    leftLeg = chr:WaitForChild("Left Leg")
    rightLeg = chr:WaitForChild("Right Leg")
    hum = chr:FindFirstChild("Humanoid")
end)]]

hum.FreeFalling:connect(function(plrFalling)
falling = plrFalling
end)

game:GetService("RunService").RenderStepped:connect(function()
camera.CoordinateFrame = CFrame.new(CFrame.new(root.Position + Vector3.new(-20,45,0)).p,root.Position)
root.CFrame = CFrame.new(root.Position, Vector3.new(mouse.Hit.p.X, root.Position.Y, mouse.Hit.p.Z))

if falling then
    local parter,pos = getBase("down");
    part.CFrame = CFrame.new(pos, pos + Vector3.new(root.CFrame.lookVector.X, 0, root.CFrame.lookVector.Z))  --[[*CFrame.Angles(0,math.rad(-90),0);]]
elseif hum.Jump == false then
    part.CFrame = (root.CFrame - (Vector3.new(0,leftLeg.Size.Y,0) + Vector3.new(0,root.Size.Y/2,0)))  * CFrame.new(-.5,0,0);
end
end)

The only issue is that the 'Invisicam' mode that sets all parts between the camera and player to translucent only seems to work in offline mode. This doesn't function at all online. And another issue is that when I reset, the camera and 'part' that is being instanced doesn't also reset. Instead the camera gets stuck and no new part is instantiated.

So I have two questions:

1.) How can I get the DevCameraOcclusionMode to properly function?

2.) How can I prevent the camera from getting stuck in one spot after the player dies?

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

To prevent the camera from getting stuck, we can wait before executing the script:

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

Also, we can make the camera subject the Humanoid, rather than the LocalPlayer.

camera.CameraSubject = plr.Character.Humanoid

Also, put the part inside the plr.Character so it gets destroyed when the player dies.

Final Script:

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

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()

local root = chr:WaitForChild("HumanoidRootPart")
local leftLeg = chr:WaitForChild("Left Leg")
local rightLeg = chr:WaitForChild("Right Leg")
local hum = chr:FindFirstChild("Humanoid")

local camera = workspace.CurrentCamera
camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable;
camera.CameraSubject = plr.Character.Humanoid;


local part = Instance.new("Part",plr.Character)
part.CanCollide = false;
part.Anchored = true;
part.FormFactor = Enum.FormFactor.Custom
part.Size = Vector3.new(7,.1,6)
part.Transparency = 1;
local gui = Instance.new("SurfaceGui",part)
gui.Face = "Top"
local decal = Instance.new("ImageLabel",gui)
decal.Size = UDim2.new(1,60,.8,0)
decal.Position = UDim2.new(.1,-20,.2,-15)
decal.Image = "http://www.roblox.com/asset/?id=276509139"
decal.BackgroundTransparency = 1;
local falling = false;

local mouse = plr:GetMouse()
mouse.TargetFilter = workspace.Map

function getBase(side)
    local sign = (side == "up" and 1 or -1);
    local ray = Ray.new(root.Position, Vector3.new(0, 1000 * sign, 0))
    local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {chr,part,camera})
    return hit,position;
end

--[[
hum.Died:connect(function()
    part:Destroy()
    chr = plr.CharacterAdded:wait()
    root = chr:WaitForChild("HumanoidRootPart")
    leftLeg = chr:WaitForChild("Left Leg")
    rightLeg = chr:WaitForChild("Right Leg")
    hum = chr:FindFirstChild("Humanoid")
end)]]

hum.FreeFalling:connect(function(plrFalling)
falling = plrFalling
end)

game:GetService("RunService").RenderStepped:connect(function()
camera.CoordinateFrame = CFrame.new(CFrame.new(root.Position + Vector3.new(-20,25,0)).p,root.Position)
root.CFrame = CFrame.new(root.Position, Vector3.new(mouse.Hit.p.X, root.Position.Y, mouse.Hit.p.Z))

if falling then
    local parter,pos = getBase("down");
    part.CFrame = CFrame.new(pos, pos + Vector3.new(root.CFrame.lookVector.X, 0, root.CFrame.lookVector.Z))  --[[*CFrame.Angles(0,math.rad(-90),0);]]
elseif hum.Jump == false then
    part.CFrame = (root.CFrame - (Vector3.new(0,leftLeg.Size.Y,0) + Vector3.new(0,root.Size.Y/2,0)))  * CFrame.new(-.5,0,0);
end
end)

To fix your DevCameraOcclusionMode problem, I modified the built in camera script to automatically go into Invisicam mode. Since there are modules and stuff inside it, I will just link you my model.

However if you want to change it yourself, these are the changes I made to the script:

--Around line 150
    --if newOcclusionMode == Enum.DevCameraOcclusionMode.Zoom then
    --  EnabledOcclusion = PopperCam
    --elseif newOcclusionMode == Enum.DevCameraOcclusionMode.Invisicam then
        EnabledOcclusion = Invisicam -- Set it to Invisicam mode
    --else
    --  EnabledOcclusion = false
    --end

Then at the beginning I added this to take out the CameraScript roblox puts in.

repeat wait() until game.Players.LocalPlayer;
for a,v in pairs(script.Parent:GetChildren()) do
    if v.Name == "CameraScript" and v ~= script then
        v:Destroy()
    end
end
0
Cheers, mate! I owe you one DigitalVeer 1473 — 9y
0
@DigitalVeer Haha thanks. Keep me posted on how what you are making turns out! Validark 1580 — 9y
Ad

Answer this question