I am trying to create a roll ability for a game which has mouse lock. Usually, the humanoidrootpart locks into the direction which the camera turns, however when you try to roll, the root unlocks and allows for turning. This mostly works as intended, until after the roll is over.
After rolling, if the player isn’t already facing the camera, they immediately snap towards it, which makes it look weird I wanted to create a way for the player to turn towards the camera before it locks in place again.
What I have currently done is hold the player and camera in place while the humanoidrootpart tweens towards the camera, however this also feels off as it prevents you from being able to look around.
However, if I do not lock the camera, you can turn during the tween, causing the same snapping appearance as before.
-- code that moves the camera, just the parts that are important
local function plrInput(_, inpState, inpObj)
if inpState == Enum.UserInputState.Change then
if RepStore:WaitForChild("stopTurn"):GetAttribute("camera") == false then
camAngX = camAngX - inpObj.Delta.X
camAngY = math.clamp(camAngY - inpObj.Delta.Y * 0.4, -75, 45)
end
end
end
if RepStore:WaitForChild("stopTurn").Value == false then
root.CFrame = CFrame.lookAt(root.Position, Vector3.new(cam.CFrame.LookVector.X * 900000, root.Position.Y, cam.CFrame.LookVector.Z * 900000))
end
-- code after roll is over
local doneEvent
doneEvent = rollAnim.Stopped:Connect(function()
doneEvent:Disconnect()
local currCam = workspace.CurrentCamera
currCam.CameraType = Enum.CameraType.Scriptable
hum.WalkSpeed = 0
local turnTween = game:GetService("TweenService"):Create(root, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {CFrame = CFrame.lookAt(root.Position, Vector3.new(cam.CFrame.LookVector.X * 900000, root.Position.Y, cam.CFrame.LookVector.Z * 900000))})
turnTween:Play()
stopTurn:SetAttribute("camera", true)
turnTween.Completed:Wait()
hum.WalkSpeed = walkSpd
currentAction.Value = not currentAction.Value
stopTurn.Value = not stopTurn.Value
stopTurn:SetAttribute("camera", false)
rollDb.Value = not rollDb.Value
end)