So I'm trying to make a third person game, and have the Player swivel around their mouse like how Third Person MMO's do it sometimes. Here's what I have, but it doesn't do what I want it to do, I kind've just spin there constantly Code:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Character; repeat wait() Character = Player.Character until Character; function UpdateRotation() Character:SetPrimaryPartCFrame(Character.PrimaryPart.CFrame*CFrame.fromEulerAnglesXYZ(0, Mouse.X, 0)) end while true do UpdateRotation() wait() end
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Character; repeat wait() Character = Player.Character until Character; local HRP = Character:WaitForChild("HumanoidRootPart") function UpdateRotation() local to = Mouse.Hit.p -- get 3D position of where the mouse aims local pos = HRP.Position -- if to is (100,200,300) and pos is (5,5,5) -- it'll give us (100,5,300) local sameHeight = Vector3.new(to.X,pos.Y,to.Z) -- CFrame.new(pos,to) gives a CFrame at pos 'pos' aiming to pos 'to' -- because our Y is the same, the Torso stays straight up, but it'll -- be rotated towards the 'to' thing HRP.CFrame = CFrame.new(pos,sameHeight) end local RS = game:GetService("RunService").RenderStepped while true do UpdateRotation() RS:wait() end