Wassup ya’ll hope you’re having a fine morning/afternoon. I’m going to get straight to the point, how do I make the player character rotate based on camera position Y, but smoothly? I have made something relatively close but its choppy because I am using CFrame angles. Thanks in adavance!
WHAT I WOULD LIKE IT TOO LOOK LIKE:
WHAT IT LOOKS LIKE:
MY CODE:
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local head = player.Character:WaitForChild("Head")
game:GetService("RunService").RenderStepped:Connect(function()
local camRender = camera:GetRenderCFrame()
local x,y,z = camRender:ToOrientation()
local diff = humanoidRootPart.Orientation.Y - math.deg(y)
if (diff > 45 and diff < 315) then
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0)
elseif (diff < -45 and diff > -315) then
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0)
end
end)
The head is already being orientated silly, did you watch the videos? I just want the humanoid root part to rotate if the camera is a certain distance from its original position like in the minecraft video.
I think I know what you mean now, you want that realistic character orientation so that if you turn to look left, the body will remain in it’s previous direction IF that direction is less than or is 45 degrees. I think that in itself should solve the issue.
more than. If the player camera has reached a certain degree, I want the character to start moving with the camera. Then when its less than it doesn’t move the character.
This seemed to work for me.
Tweak it so it works with your script.
local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")
game:GetService("RunService").RenderStepped:Connect(function()
local camRender = workspace.CurrentCamera.CFrame
local x, y, z = camRender:ToOrientation()
local diff = humanoidRootPart.Orientation.Y - math.deg(y)
if (diff > 45 and diff < 315) or (diff < -45 and diff > -315) then
humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0), .1)
end
end)
repeat task.wait() until player.Character
local TweenService = game:GetService("TweenService")
local tween_info = TweenInfo.new(
.2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local head = player.Character:WaitForChild("Head")
game:GetService("RunService").RenderStepped:Connect(function()
local camRender = camera:GetRenderCFrame()
local x,y,z = camRender:ToOrientation()
local diff = humanoidRootPart.Orientation.Y - math.deg(y)
if (diff > 45 and diff < 315) then
TweenService:Create(humanoidRootPart, tween_info, {
CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0)
}):Play()
elseif (diff < -45 and diff > -315) then
TweenService:Create(humanoidRootPart, tween_info, {
CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0)
}):Play()
end
end)
I tested it, and it worked fine, see if this is what you want (you can also edit some settings to be more like you want)