This is better since this way you can actually stop the connection.
Okay, Iâll test that right now.
Iâve never really used these kinds of connections before, how would I implement this into my script?
Would I do
Connection = game:GetService("RunService").Heartbeat:Connect(function()
Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)
end)
?
This is unnecessary just store this on a variable like local RunService = game:GetService("RunService")
.
I know. Iâll do that right now
By the way it works, the camera is still constantly spinning though. Any idea on an in check to see if it should be done or not? This might be because I forgot to play the tween⌠whoops
You could try to print if the connection is still running. If it still running then the tween does not have a problem itâs the connection still not disconnected.
Ok so the camera locks in place and rotates to the left a bit, then locks back onto the character and starts spinning, here is the code.
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")
local Tilting = false
local Cooldown = false
local Camera = game.Workspace.CurrentCamera
local Connection
UIS.InputBegan:Connect(function(i,g)
if i.KeyCode == Enum.KeyCode.E and not g and Cooldown == false then
Cooldown = true
delay(2,function()
Cooldown = false
end)
if Tilting == true then
TS:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.Angles(0,0,0)}):Play()
Connection:Disconnect()
else
TS:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)}):Play()
Connection = RS.Heartbeat:Connect(function()
Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)
end)
end
Tilting = not Tilting
end
end)
Thatâs because you have to change the Cameraâs type to scriptable.
I changed it to scriptable and it no longer locks onto the character at all until you press E again
Thatâs because scriptable disables the built-in camera module.
So how would I lock it on to the character while rotating it, or re enable the camera module? Although I guess that defeat the purpose of âscriptableâ doesnât it.
You would instead use the HumanoidRootPart/Headâs position:
CFrame.Angles(0, math.rand(10), 0) * HumanoidRootPart.Position
Zoom in and out no longer work so you would have to modify that yourself aswell.
Ok, so the heartbeat, instead of setting the cameras position, it multiplies it.
I think this is the reason why itâs spinning, and will also fling the camera into the air
If I remove the second âCamera.CFrameâ then it wonât fling into the air but it stills spins, not in third person though. But it is now offset from the correct position of the character.
As I have said you would want to use the humanoidâs root part not the camera.
I canât use the HRPâs position, I have to use itâs CFrame, would this cause an issue (The reason i have to use it is the script will break otherwise)
Not the CFrame the position, if you want to you could use the HumanoidRootPartâs CFrame.
The canât use the HRPâs Position âUnable to assign property CFrame. CoordinateFrame expected, got Vector3â
Instead of multiply on CFrame.Angles(0, math.rand(10), 0) * HumanoidRootPart.Position
try addition.