How to make the character rotate with the cursor?

I am asking for is that the player’s character will rotate depending on the location of the cursor. It’s kind of like first person character rotation with the cursor but with the cursor being actually moving and not in the center (basically third person). I’ve seen some solutions but they seem to have the heads, arms, or legs only moving.

1 Like

you can achieve character rotation with the cursor using the UserInputService. Here’s a basic example:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- Adjust the sensitivity of rotation
local rotationSpeed = 0.5

-- Function to rotate the character based on the mouse movement
local function rotateCharacterWithMouse()
    local mouseDelta = UserInputService.InputChanged:Wait()
    local deltaRotation = Vector3.new(0, mouseDelta.Delta.x, 0) * rotationSpeed

    -- Get the primary part (assumes it's the HumanoidRootPart)
    local primaryPart = character:FindFirstChild("HumanoidRootPart") or character.PrimaryPart

    -- Check if the primary part exists before applying rotation
    if primaryPart then
        primaryPart.CFrame = primaryPart.CFrame * CFrame.Angles(0, -math.rad(deltaRotation.y), 0)  -- Inverted the sign
    end

    -- Update the humanoid's move direction based on the rotation
    local forwardVector = primaryPart.CFrame.LookVector
    humanoid:Move(Vector3.new(forwardVector.x, 0, forwardVector.z))
end

-- Connect the function to the mouse movement
UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        rotateCharacterWithMouse()
    end
end)

Now, the line primaryPart.CFrame = primaryPart.CFrame * CFrame.Angles(0, -math.rad(deltaRotation.y), 0) has a negative sign before math.rad(deltaRotation.y), which should make the character rotate in the same direction as the mouse movement.

1 Like

Sorry for the late reply,

I think my wording was a bit vague, so I’ll try to clear up what I actually want. So let’s say I have these two screenshots:


Do you notice how the cursor moved? Yeah, that’s how I want the character to rotate as the cursor changes (sorry if the character is not aligned) in position with regards to its X and Y axis and not by just right clicking to align the character with the cursor. So its basically cursor movement and where it moves the character will look towards it with rotation adjusted for it.

Ok, so I’ve found the solution I wanted by just looking at some post, here is the post in question:

The solution in the post states to rotate the character based on mouse movement is to change the CFrame of the root part with the X and Z axis changed with the hit position of the mouse, but the Y axis remains constant as before everything was changed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.