Hello once again DevForum, today I have an issue where i can’t rotate the camera without breaking the default behavior of the camera.
What I’m trying to achieve is an effect like in Evade, where the camera tilts left or right depending on which direction the player is running.
Failure:
(The camera breaks when pressing A or D)
Script:
local CameraTilt = CFrame.Angles(0, 0, math.rad(0,0,0))
local CameraTiltTween = TweenService:Create(
PlayerCamera,
TweenInfo.new(0.25),
{
CFrame = PlayerCamera.CFrame * CameraTilt
}
)
if ActionName == "CameraTiltLeft" then
if InputState == Enum.UserInputState.Begin then
ContextActionService:UnbindAction("CameraTiltRight")
CameraTilt = CFrame.Angles(0,0,math.rad(15))
CameraTiltTween:Play()
return Enum.ContextActionResult.Pass
elseif InputState == Enum.UserInputState.End then
CameraTilt = CFrame.Angles(0,0,math.rad(-15))
CameraTiltTween:Play()
ContextActionService:BindAction("CameraTiltRight", ActionHandler, true, Enum.KeyCode.D)
return Enum.ContextActionResult.Pass
end
elseif ActionName == "CameraTiltRight" then
if InputState == Enum.UserInputState.Begin then
ContextActionService:UnbindAction("CameraTiltLeft")
CameraTilt = CFrame.Angles(0,0,math.rad(-15))
CameraTiltTween:Play()
return Enum.ContextActionResult.Pass
elseif InputState == Enum.UserInputState.End then
CameraTilt = CFrame.Angles(0,0,math.rad(15))
CameraTiltTween:Play()
ContextActionService:BindAction("CameraTiltLeft", ActionHandler, true, Enum.KeyCode.A)
return Enum.ContextActionResult.Pass
end
end