I’m having this issue with my Third Person Camera system, which overlays my camera animations. Basically, how the Third person camera works is by using the .RenderStepped event, I think this is the cause of the issue - it keeps overlaying the camera animations, therefore the camera anims aren’t or barely noticeable. The only thing that makes it work is by adding a wait() but then the third person system won’t be ran as smooth as it should be.
I’m sure there is a way to go over this, since it works perfectly fine with when you enable shift lock on Roblox’s own camera system.
Not sure why you would need the code? I’ll provide a few visual references if needed.
Here’s the code of the TPC briefly:
game:GetService("RunService").RenderStepped:Connect(function()
wait() --// If removed, this will completely overlay my ingame camera animations.
--// function that puts the camera to the given offset etc.
end)
This is probably issue with the code itself. But you have yet to provide the full code so we are not well equipped to help you with your problem. Of course we need to see the code.
game:GetService("RunService").RenderStepped:Connect(function()
wait()
if Plr.Character:FindFirstChild("Humanoid").Health > 0 then
local rootPart = Plr.Character:FindFirstChild("HumanoidRootPart")
local Enabled = script:WaitForChild("Enabled").Value
if Plr.Character and rootPart then
if Enabled == true then --//If enabled then lock the camera
Deb = true
Cam.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
--Set rotated start cframe inside head
local cameraPos = CameraPosition
local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)
--Set camera focus and cframe
local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,cameraPos.Z))
local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,-50000))
Cam.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
elseif Enabled == false then
if Deb == true then Deb = false
Cam.CameraSubject = Plr.Character:WaitForChild("Humanoid")
Cam.CameraType = "Custom"
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end
end
if TurnCharacterToMouse == true then
if not Mobile then
Hum.AutoRotate = false
Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
else
Hum.AutoRotate = true
local camRotation = math.atan2(-Cam.CFrame.lookVector.X, -Cam.CFrame.lookVector.Z)
Core.CFrame = CFrame.new(Core.Position) * CFrame.Angles(0, camRotation, 0)
end
else
Hum.AutoRotate = true
end
end
end)
``
Because there are some variables missing, I can’t properly test this as you are with your whole system. However, I’ve cleaned up the code you provided and implemented some logic fixes that I think might help. If it doesn’t, I’m sorry I couldn’t be of more help. I just simply can’t get the result you’re obtaining.
local plr = game:GetService("Players").LocalPlayer;
local cam = workspace.CurrentCamera;
local input = game:GetService("UserInputService");
local CameraPosition = Vector3.new(); -- Your Camera Position.
local xAngle = 45; -- Your X Angle.
local yAngle = 45; -- Your Y Angle.
local onMobile = function() end -- Fancy mobile detection code.
local UpdateSpeed = 3; -- Update speed.
local Core = nil; -- Core?
local pMouse = plr:GetMouse(); -- Player mouse.
local lockEnabled = true;
local turnCharToMouse = true;
local function cameraStep()
if not (plr.Character or plr.Character:FindFirstChild("HumanoidRootPart")) then return end
local rp = plr.Character:FindFirstChild("HumanoidRootPart");
-- //: I added this so it redefines every time. It also waits if there isn't a Humanoid because, why run the loop without a Humanoid?
local hum = plr.Character:WaitForChild("Humanoid");
-- //: If enabled, camera locks.
if lockEnabled == true then
cam.CameraType = Enum.CameraType.Scriptable;
input.MouseBehavior = Enum.MouseBehavior.LockCenter;
-- //: Set rotated start of CFrame inside of head.
local cameraPos = CameraPosition;
local startCFrame = CFrame.new((rp.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)
-- //: Set Camera Focus/CFrame
local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,cameraPos.Z));
local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,-50000));
cam.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p);
else
-- //: Normal Camera
cam.CameraSubject = plr.Character:WaitForChild("Humanoid");
cam.CameraType = Enum.CameraType.Custom;
input.MouseBehavior = Enum.MouseBehavior.Default;
end
if turnCharToMouse == true then
if not onMobile then
hum.AutoRotate = false;
Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(pMouse.Hit.p.x, Core.Position.Y, pMouse.Hit.p.z)), UpdateSpeed / 2);
else
hum.AutoRotate = true;
local camRotation = math.atan2(-cam.CFrame.lookVector.X, -cam.CFrame.lookVector.Z)
Core.CFrame = CFrame.new(Core.Position) * CFrame.Angles(0, camRotation, 0);
end
else
hum.AutoRotate = true;
end
-- //: Our suspicious wait().
wait();
end
game:GetService("RunService"):BindToRenderStep("cameraStep",1,cameraStep);
EDIT: If the result you require is removing the wait() parameter, please do so.