I Have decided to try some camera manipulation.
I Wanted to try out making an A/D Script of when the character presses a button it will rotate the camera to a specific side.
Heres what I made so far:
local camera = game.Workspace.CurrentCamera
local input = game:GetService("UserInputService")
local h = script.Parent.Humanoid
camera.CameraType = Enum.CameraType.Custom
wait(0.1)
CFrame.Angles(math.rad(0),math.rad(0),math.rad(3))
input.InputBegan:Connect(function (key)
local k = key.KeyCode
if k == Enum.KeyCode.A then
camera.CameraSubject = h
print("A")
camera.CFrame = game.Workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(0),math.rad(0),math.rad(10))
end
end)
input.InputEnded:Connect(function (key)
local k = key.KeyCode
if k == Enum.KeyCode.A then
print("A Stopped")
camera.CFrame = game.Workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(0),math.rad(0),math.rad(-10))
end
end)
When you set CameraType to Scriptable, the camera stops following your character. If you were to set CameraType to scripted, then you would have to make the camera follow the character manually. Instead of setting the CameraType, just let the default roblox camera follow the character and update the rotation.
My solution:
local camera = game.Workspace.CurrentCamera
local input = game:GetService("UserInputService")
local h = script.Parent.Humanoid
local angle = 0
input.InputBegan:Connect(function (key)
local k = key.KeyCode
if k == Enum.KeyCode.A then
print("A")
angle = 10--set the new angle
end
end)
input.InputEnded:Connect(function (key)
local k = key.KeyCode
if k == Enum.KeyCode.A then
print("A Stopped")
angle = 0--set angle back to 0
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
--update camera cframe
camera.CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(angle))
end)--run on every frame because the camera will constantly update to new character position
Basically what I’ve done is set the angle to 10 when “A” is pressed and have the cframe be updated every frame.
I hope this helped!