Smoothly turning character back into place

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)
1 Like

You could make a temporary RenderStepped connection that updates the tween to use the rotation the player is trying to look.

While I could update the goal for the tween which allows camera movement, the tween locks the humanoidrootpart in place in order to turn it. This would mean that the player would be unable to move at all until the humanoidrootpart lines up with the camera.

Alright, after looking through my code and noticing how other turning works, such as the arms, I have decided that I will just lerp the humanoidrootpart. This will allow me to change the turning speeds as well so that I can have both a faster turn while walking and a slower turn while recovering from a roll.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.