I am currently trying to find a way to make a players character face the mouse while rotating their character on all axes.
I’ve tried using this script:
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local connection
local Mouse = game.Players.LocalPlayer:GetMouse()
local RunService = game:GetService("RunService")
connection = RunService.RenderStepped:Connect(function()
local RootPos, MousePos = Character.HumanoidRootPart.Position, Mouse.Hit.Position
Character.HumanoidRootPart.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end)
This works, but doesn’t rotate the character fully:
Like I said, I want to be able to rotate the character fully on all axes. I intend to use this when the character is stationary and cant move, mainly for throwing projectiles.
you would have to anchor the HumanoidRootPart and use they y-axis of the mouse’s hit position.
this would be the result:
the goods:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Connection
local function ToggleMovement(boolean: boolean)
print(boolean)
if boolean then
Connection = RunService.RenderStepped:Connect(function()
local RootPos, MousePos = Character.HumanoidRootPart.Position, Mouse.Hit.Position
Character.HumanoidRootPart.Anchored = true
Character.HumanoidRootPart.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, MousePos.Y, MousePos.Z))
end)
else
if Connection then
Character.HumanoidRootPart.Anchored = false
Connection:Disconnect()
end
end
end
-- this is just for testing
task.wait(10)
ToggleMovement(true)
task.wait(4)
ToggleMovement(false)