How would i make the character face the mouse like the world of magic

the title says it all how would i make the character face the mouse position

1 Like
local plr = game.Players.LocalPlayer
local char = plr.Character
local hrp = char.HumanoidRootPart
local mouse = plr:GetMouse()
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	local hrpPos, mousePos = hrp.Position, mouse.Hit.Position
	hrp.CFrame = CFrame.new(hrpPos, Vector3.new(mousePos.X, hrpPos.Y, mousePos.Z))
end)

Should fix your problems

3 Likes

This is simple. You can get the mouse position in a LocalScript like this:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Position = Mouse.Hit.Position

And you can face the players character towards the Position like this:

character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, Position)

The first script gets the players mouse using :GetMouse(), and creates a variable called Position which is the position of the mouse in world space.

The second script gets the CFrame of the character’s humanoidrootpart (which is basically the root of the character), and sets it’s CFrame to a new CFrame.new() that is positioned at it’s own position and facing Position.

If you want to make an object rotate on a specific axis towards an object, just use this method:

character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, Vector3.new(Position.X, character.HumanoidRootPart.Position.Y, Position.Z)) -- if you wanted to rotate it on the *y* axis.

There you go, I hope I helped.

4 Likes