Still have questions? Join our Discord server and get real time help.
1

# How do i point the head torwards the mouse's position?

Teeter11 260
5 years ago

When this code runs there is no error but, I am trying to make the code make the players head stay in the position its at but point to the mouse. What happens is the players head moves to the position of the mouse not facing it.

Tool = script.Parent
Player = game.Players.LocalPlayer
Camera = game.Workspace.CurrentCamera
Mouse = Player:getMouse()
Tool.Equipped:connect(function()
local weld1 = Instance.new("Weld")
weld1.Part1 = Player.Character.Torso
while wait() do
end
end)


It would help a lot if you helped! Thanks!

1
MrNicNac 855
5 years ago

All too much do you see people editing the C0 and setting the Part0 to what I consider "incorrect" things. The Part0 should be the "anchoring" part. For instance, all things should be "anchored" to the torso. Part1 should be the legacy (attachment) part.

C1 is also the value should be edited. Not C0. C0 is the location (relative to Part0's CFrame) of where the two parts will be connected. C1 is the offset from that location.

Tool = script.Parent
Player = game.Players.LocalPlayer
Camera = game.Workspace.CurrentCamera
Mouse = Player:getMouse()

Tool.Equipped:connect(function()
local weld1 = Instance.new("Weld")
weld1.Parent = Game.JointsService
weld1.Part0 = Player.Character.Torso
while wait() do
end
end)

0

All right, I agree with what the Doc has to say about switching the "Part0" and "Part1". The Torso should always be your anchoring point.

Anyways, I've been the exact same position as you because I tried this same idea. Alright so you know how a weld works correct?

weld.c1 is part1 relative position to part0 but... the cframe your head would be like CFrame.new(0,-1.5,0)yes? When you take the CFrame of the head on line 11 you take its position which maybe Vector3.new(3525,214,1321) so that may be why your head may be displaced.

This is what I figured you should do...

To get the Direction of your head to your mouse you should use this. Vector3 math (;

local dir = (Player.Character.Head.CFrame.p-mouse.Hit.p).unit

Now we have our direction but when you apply it to your script. weld1.C1 = CFrame.new(Vector3.new(0,-1.5,0), Vector3.new(0,-1.5,0) + dir)