Well, the mouse's lookVector is constantly changing, so just setting the Orientation of the player's HumanoidRootPart will not keep them in sync. Instead, you can try this
First, to check how much the player's mouse will affect movement (higher numbers will make you spin too much), you set _G.MouseSensitivity to 0 (changing this value will make the camera move with the mouse)
Next, we have a few functions to make the mouse move with the camera when not set to 0
Then you will need to check the hit.p of the mouse for the player to move with it (as seen in the Mouse.Move Event)
This LocalScript will move the player to match the mouse, along with some functions to change the camera
_G.MouseSensitivity = 0
_G.MouseSensitivityOffset = 0
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()
function RotateCamera(x, y)
Camera.CoordinateFrame = CFrame.new(Camera.Focus.p) * (Camera.CoordinateFrame - Camera.CoordinateFrame.p) * CFrame.Angles(x, y, 0) * CFrame.new(0, 0, (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude)
end
function GetAngles(cf)
local lv = cf.lookVector
return -math.asin(lv.y), math.atan2(lv.x, -lv.z)
end
local LastCF = Camera.CoordinateFrame
function UpdateSensitivity()
if _G.MouseSensitivity ~= 1 then
local x, y = GetAngles(LastCF:toObjectSpace(Camera.CoordinateFrame))
Camera.CoordinateFrame = LastCF
RotateCamera(x * -(_G.MouseSensitivity + _G.MouseSensitivityOffset), y * -(_G.MouseSensitivity + _G.MouseSensitivityOffset))
LastCF = Camera.CoordinateFrame
end
end
Mouse.Move:connect(function()
UpdateSensitivity()
local root = Player.Character.HumanoidRootPart
Player.Character:SetPrimaryPartCFrame(CFrame.new(root.Position, (Mouse.Hit.lookVector*Vector3.new(1,0,1)) + (root.Position*Vector3.new(0, 1, 0))))
end)
Mouse.Idle:connect(function()
LastCF = Camera.CoordinateFrame
end)
You can change "lookVector" to "p" if you want the player to rotate with the mouse as well
I will also note that the "lookVector" doesnt not function properly if the player begins to move, so using "p" is probably the preferred method.
Also, if you don't need to deal with the camera, then only this section is required
_G.MouseSensitivity = 0
_G.MouseSensitivityOffset = 0
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Move:connect(function()
local root = Player.Character.HumanoidRootPart
Player.Character:SetPrimaryPartCFrame(CFrame.new(root.Position, (Mouse.Hit.lookVector*Vector3.new(1,0,1)) + (root.Position*Vector3.new(0, 1, 0))))
end)
7 comments
Dont just modify the HRP, use the SerPrimaryPartCFrame function
Modifying the HRP or using the "SetPrimaryPartCFrame" function in the exact same way for this script, but ok, i adjusted it to match
that is a myth actually, just modifying the primary part of any model directly produces a different result than modifying the model with SetPrimaryPartCFrame
of course, the results are the same if the model is only made of one part
lol, well in studio it works fine with the HRP changed, so it obviously isnt broken by doing that. Maybe it's just some property of the game's player though, idk
A piece of that final code was perfect. I messed around with it, changing lookVector to p, and putting this in a while loop to make sure it's activated at all times.
Awesome! Glad I could help.