Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this Swivel Around Mouse work?

Asked by 6 years ago
Edited 6 years ago

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
0
Instead of character.PrimaryPart.CFrame use character:GetPrimaryPartCFrame() Programical 653 — 6y
0
Thank's, but that still doesn't change the fact that my guy is just spinning constantly TheShiningSavior 10 — 6y

1 answer

Log in to vote
0
Answered by
einsteinK 145
6 years ago
Edited 6 years ago

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
Ad

Answer this question