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

How do you make the head follow your mouse?

Asked by 4 years ago
Edited 4 years ago

I tried it doesn't work, It only moves the head, Not the rotation, Please help My Code:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Motor = script.Parent:WaitForChild("Torso"):WaitForChild("Neck")

while true do
    wait()
    Motor.C1 = CFrame.new(0, -0.5, 0, -1, 0, 0, 0, 0, 1, 0, 1, -0) + Mouse.Hit.LookVector
end

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think this should work, this is Code I found some time ago. It was originally written to rotate entire character so I changed it for only head, so I don't know how it will work

local player = game.Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")

local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:wait()

local Head= character:WaitForChild("Head")

character:WaitForChild("Humanoid").AutoRotate = false


local gyro = Instance.new("BodyGyro",Head)
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
gyro .MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
gyro .P = 10000

game:GetService("RunService"):BindToRenderStep(
    "Updategyro ",
    Enum.RenderPriority.Character.Value,
    function()

        gyro .CFrame =
        CFrame.Angles(
            0,
            math.atan2(
                Head.CFrame.X-mouse.Hit.X,
                Head.CFrame.Z-mouse.Hit.Z
            ),
            0
        )
end)

game:GetService("RunService"):BindToRenderStep(
    "UpdateNeckC1",
    Enum.RenderPriority.Character.Value,
    function()
        character.UpperTorso.BodyFrontAttachment.CFrame =
        CFrame.new(0,-0.5,0,-1,0,0,0,0,1,0,1,-0)
        *CFrame.Angles(
            -math.atan2(
                character.UpperTorso.BodyFrontAttachment.CFrame.Position.Y-mouse.Hit.Y,
                math.sqrt((character.Head.CFrame.X-mouse.Hit.X)^2+(character.Head.CFrame.Z-mouse.Hit.Z)^2) --Distance formula
            ),
            0,
            0
        )
end)

0
It breaks. FixRobloxz 61 — 4y
0
what do you mean by that? GooierApollo664 183 — 4y
0
It does error lol FixRobloxz 61 — 4y
0
what does it say? GooierApollo664 183 — 4y
View all comments (12 more)
0
Workspace.FixRobloxz.LocalScript:6: bad argument #2 to '?' (Vector3 expected, got CFrame) FixRobloxz 61 — 4y
0
I changed it GooierApollo664 183 — 4y
0
It does worse. I need the head to look at the mouse. FixRobloxz 61 — 4y
0
Ok I'm changing everything I think I know how to fix this GooierApollo664 183 — 4y
0
I use motor6d bruh. FixRobloxz 61 — 4y
0
use My script GooierApollo664 183 — 4y
0
That Script? It doesnt work aaaaaaaaaaaaaaa FixRobloxz 61 — 4y
0
What do you mean by that? GooierApollo664 183 — 4y
0
then set desired angle of motor6d that CFrame.Angles( math.atan2( Head.CFrame.Y+mouse.Hit.Y, Head.CFrame.Z-mouse.Hit.Z ) GooierApollo664 183 — 4y
0
I tried it before, I want it to look up and down FixRobloxz 61 — 4y
0
For just up and down, make Y and X axis 0 GooierApollo664 183 — 4y
0
Nah, I already did it. :/ FixRobloxz 61 — 4y
Ad

Answer this question