Is there a way to tween the HumanoidRootPart orientation without tweening the position?

I’m trying to make a forced shift lock when you equip a tool:

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local tool = script.Parent
local equipped = false
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

local shiftLockTweenInfo = TweenInfo.new(.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)

RunService.RenderStepped:Connect(function()
	if equipped == true then
		local _, y = camera.CFrame.Rotation:ToEulerAnglesYXZ()
		shiftLockTween = TweenService:Create(player.Character.HumanoidRootPart, shiftLockTweenInfo, {CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.Angles(0,y,0)})
		shiftLockTween:Play()
	end
end)

tool.Equipped:Connect(function()
	equipped = true
end)
tool.Unequipped:Connect(function()
	equipped = false
	shiftLockTween:Cancel()
end)

The code works almost perfect although because the shiftLockTween also tweens the humanoidrootpart’s position it makes the player slower, trying to tween them back into a previous position.

Does anyone have any remedy for this?

Edit: Also I would rather not using some sort of module. Just this script alone.

Since you’re on RenderStepped, you can just set the CFrame manually, like this:

RunService.RenderStepped:Connect(function(deltaTime: number) 
	if equipped == true then 
		player.Character.HumanoidRootPart.CFrame = CFrame.lookAlong(player.Character.HumanoidRootPart.Position, Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z))
	end	
end)

Note that this would make it so that your character would always face towards the camera direction, instantly.

If you want some smoothing involved, you could do this:

local function smoothLerp(variableA: any, variableB: any, fraction: number, deltaTime: number)
	local f = 1.0 - math.pow(1.0 - fraction, deltaTime)
	if (type(variableA) == "number") then
		return ((1-f) * variableA) + (variableB * f)
	end
	return variableA:Lerp(variableB, f)
end

RunService.RenderStepped:Connect(function(deltaTime: number) 
	if equipped == true then 
		player.Character.HumanoidRootPart.CFrame = 
			smoothLerp(
				player.Character.HumanoidRootPart.CFrame,
				CFrame.lookAlong(player.Character.HumanoidRootPart.Position, Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z)),
				0.95,
				deltaTime
			)
	end	
end)
1 Like

ended up forking this guy’s script
and got

--// Player Info

local player       = game:GetService("Players").LocalPlayer
local character    = player.Character or player.CharacterAdded:Wait()
local rootPart     = character:WaitForChild("HumanoidRootPart")
local camera       = game:GetService("Workspace").CurrentCamera
local runService   = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
local humanoid     = character:WaitForChild("Humanoid")
local tool = script.Parent

--// Shift Lock Function
local function shiftLock(toggle)

	local function lock()

		local lookVector = camera.CFrame.LookVector

		local rootPos = rootPart.Position; local distance = 900

		--rootPart.CFrame = CFrame.new(rootPos, lookVector * Vector3.new(1, 0, 1) * distance)

		shiftLockTween = tweenService:Create(rootPart, TweenInfo.new(.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CFrame = CFrame.new(rootPos, lookVector * Vector3.new(1, 0, 1) * distance)})
		shiftLockTween:Play()
	end

	if toggle then

		runService:BindToRenderStep("ShiftLock", 200, lock)

	else

		runService:UnbindFromRenderStep("ShiftLock")

	end; humanoid.AutoRotate = not toggle

end -- enabling shift lock

tool.Equipped:Connect(function()
	shiftLock(true)
end)
tool.Unequipped:Connect(function()
	shiftLock(false)
	shiftLockTween:Cancel()
end)

idk how it works but I’m not complaining :person_shrugging:

Wouldn’t that not be smooth though? This would just constantly make it face where the camera is facing.

I just edited my reply when I noticed the smoothing part :sweat_smile:

1 Like

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