How to make the player turn with the camera when using a custom 3rd person camera

  1. What do you want to achieve? Setting the player’s rotation to the rotation of the camera, like how shift lock works

  2. What is the issue? I have tried alot of things, and have looked on the devforum. My current script makes the player look at the camera, and the offset causes the player to get sent flying

  3. What solutions have you tried so far? Searching on devforum for solutions like the ones below
    LookVector and how to use it
    What is the best way to make the player face the camera lookvector?(custom shift lock) - #4 by polill00

Script Below

local Workspace = workspace
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = Workspace.CurrentCamera
local UIP = game:GetService("UserInputService")
--UIP.MouseBehavior = Enum.MouseBehavior.LockCenter <-- ignore this

local function OnRenderStep()
	--Camera.CFrame = Camera.CFrame * CFrame.new(3,0.5,0) <-- old offset 
	Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.Position, Camera.CFrame.Position) --* CFrame.new(3,0.5,0)
end

RunService.RenderStepped:Connect(OnRenderStep)

If you can give me any devforum posts that could help me with this, it would be greatly appreciated, thanks!

1 Like

So what you’re doing right now is just getting the camera’s position and getting the rootpart to face that. I think you want to use the camera’s LookVector instead (What the camera’s pointed at, not where the camera is)
I don’t know if this is exactly what you were going for, since you’re not using angularvelocity, but this script rotates the player purely on the y axis so it doesn’t do that weird flopping thing your old script did
lmk if you have other questions but you should be able to modify this to mimic the old method you used for turning pretty easily

local Workspace = workspace
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Camera = Workspace.CurrentCamera

local attachment = Instance.new("Attachment")
attachment.Parent = HRP


local angularVelocity = Instance.new("AngularVelocity")
angularVelocity.Attachment0 = attachment
angularVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
angularVelocity.MaxTorque = math.huge
angularVelocity.AngularVelocity = Vector3.new(0,0,0)
angularVelocity.Parent = HRP


local turnSpeed = 12

RunService.RenderStepped:Connect(function(dt)
	
	local camLook = Camera.CFrame.LookVector

	local flatLook = Vector3.new(camLook.X, 0, camLook.Z)
	if flatLook.Magnitude < 0.001 then
		return
	end
	flatLook = flatLook.Unit


	local charLook = HRP.CFrame.LookVector
	local flatCharLook = Vector3.new(charLook.X, 0, charLook.Z).Unit

	
	local cross = flatCharLook:Cross(flatLook)
	local dot = flatCharLook:Dot(flatLook)
	local angle = math.atan2(cross.Y, dot)
	
	angularVelocity.AngularVelocity = Vector3.new(0, angle * turnSpeed, 0)
end)

1 Like

This seems to be working quite well, but is there any way I could add a camera offset to it? Like having it be 3 studs to the right?
Edit: I have got the offset to work by just adding the old camera offset to it, thanks!

sorry for the late reply :sweat_smile:

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