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

How do you fix the rolling of a player's head in a head rotation script when looking 90 degrees?

Asked by 5 years ago

Hey guys,

So I was working on a head movement script that rotates the Neck Motor6D of the player's character based on the Camera LookVector. The script I developed works, and uses the Cross Product of the Camera LookVector and the HumanoidRootPart LookVector.

The y component of the Cross Product is equal to the Sine of the angle between the two vectors, meaning I can obtain the angle that I am looking at. This only works because both LookVectors are Unit Vectors, meaning they have a magnitude of 1.

Since the cross product is the sine of the angle between the Camera LookVector and the HumanoidRootPart LookVector, all I have to do is get the inverse sine of the cross product's Y component to get the angle needed to rotate in the XZ plane.

The problem with this however, is that when the character's head is rotated 90 degrees in the yaw and you try rotating pitch, the head starts rolling rather than looking up and down. You can see this here:

https://gyazo.com/7bc8a834ebfe1fd0c6fc8e568a4b2a48

My question is how I can fix this so that the player's head rotates up and down how it should rather than rolling.

Here is my Head Rotation script:

01local RunService = game:GetService("RunService")
02local Player = game.Players.LocalPlayer
03repeat wait() until Player.Character
04local Character = Player.Character
05local Mouse = Player:GetMouse()
06local Camera = workspace.CurrentCamera
07 
08 
09 
10local HumanoidRootPart = Character.HumanoidRootPart
11local Head = Character.Head
12 
13 
14local Neck = Head:WaitForChild("Neck")
15local NeckOrigin = Neck.C0
View all 26 lines...

I hope someone can answer this question, it would really help me a lot. I've been stuck on this for a while, and I haven't had a linear algebra class I'm still in highschool lmao

Answer this question