Please note you have a typo on line 7 of your snippet. It probably should read:
local neck = person.Head.Neck
In addition, the Neck weld is actually stored in the Torso, rather than the Head.
and on line 8, you should just use neck.C0, not neck.NECK.C0. Snaps have no NECK property.
The position that a mouse is pointing at is Mouse.Hit.p.
We are going to inform the neck's weld based on this position.
However, we cannot simply directly use the mouse position. It's relative to the origin (a random space in the world) when we need it to be relative to the resting position of the head.
We know the target looking direction is looking from the position of the head and to the mouse. There's a CFrame constructor for this.
looking = CFrame.new( person.Head.Position , Mouse.Hit.p )
Again, though, this is relative to the origin, not the weld.
ROBLOX's default neck snaps are sort of strange, so we're going to just reset them to make them work nice.
Now we can just use the toObjectSpace method of CFrames to get what we need for C1:
neck.C1 = CFrame.new();
neck.C0 = CFrame.new(0, 1.5, 0);
neck.C0 = CFrame.new(0, 1.5, 0) * person.Head.CFrame:toObjectSpace(
looking
)
And that's that!
This will look up and down, too, though. If you don't want that, or maybe you just want to reduce the amount, you can modify looking.
from = person.Head.Position
to = Mouse.Hit.p
displacement = to - from
displacement = displacement * Vector3.new(1, 0.1 , 1)
to = from + displacement
looking = CFrame.new(from, to)
5 comments
Sorry, but there's it's labeled as neck and NECK. Its a custom mech with Motor6D's. Neck is the part while NECK is the Motor6d. This is not a Humanoid object. It's a vehicle.
Sorry, but there's a reason why it's*
BTW, what is "looking" mouse.hit.p?
Nvm on the looking, didnt see the variable.
Doesnt work. It spazzes the head. And it's not facing in the direction pointed.