I have already made a similar post and made something close to what I wanted to achieve, although, I still have one small problem.
There is a localscript I used from this post:
But I would like to get a short explanation on how to make this work for R6.
I am only trying to get the body to rotate left or right after looking too far.
^^^
I want to achieve this but for R6
The code in the post above:
-- StarterCharacterScripts
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local char = player.Character
local human = char:WaitForChild("Humanoid")
local rootPart = char.PrimaryPart
local upperTorso = char:WaitForChild("UpperTorso")
local waistJoint = upperTorso:WaitForChild("Waist")
-- Services
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
-- Globals
local currentSpeed = 0;
local currentTween = nil;
human.AutoRotate = false
human.Running:Connect(function(speed)
currentSpeed = speed
if speed > 0 then
human.AutoRotate = true
end
end)
human.Running:Connect(function(speed)
currentSpeed = speed
if speed <= 0 then
human.AutoRotate = false
end
end)
local originalWaistC1 = waistJoint.C1
local maxRotation = math.rad(85)
runService:BindToRenderStep("vanityCamera", 400, function()
local targetPosition = (cam.CFrame * CFrame.new(0,0,-1000)).p
local torsoFront = rootPart.CFrame.LookVector
local torsoRight = rootPart.CFrame.RightVector
local vectorToTarget = (targetPosition - rootPart.Position)
local rotation = math.atan2(torsoRight:Dot(vectorToTarget), torsoFront:Dot(vectorToTarget))
-- Clamp the rotation
if (rotation < -maxRotation) then
rotation = -maxRotation
elseif (rotation > maxRotation) then
rotation = maxRotation
end
if (math.abs(rotation) == maxRotation and currentSpeed <= 0.5) then
-- Rotate the bottom half to face the new direction
local newRootPartCFrame = CFrame.new(rootPart.Position, Vector3.new(
targetPosition.X, rootPart.Position.Y, targetPosition.Z
))
currentTween = tweenService:Create(rootPart, TweenInfo.new(0.33), {
CFrame = newRootPartCFrame
})
currentTween:Play()
else
if (currentTween and currentSpeed > 0.5) then
if (currentTween.PlaybackState == Enum.PlaybackState.Playing) then
currentTween:Cancel()
end
end
waistJoint.C1 = CFrame.Angles(0,rotation,0) * originalWaistC1
end
end)