So I’ve been searching around and found a way to determine angle between 1 vector and 2nd vector but I can’t seem to either correctly use it or apply it, I am attempting to get the angle between your torso and a flying brick which then the script calculates the angle and through modifying the WaistConstraint will rotate your torso to the needed angle to generally look at the brick
local CameraLookVector = RotateTo.Position
local HeadLookVector = plr.Character[WeaponName].Barrel.Position
Remotes.ReadyToRotate:FireClient(plr, math.acos( CameraLookVector:Dot(HeadLookVector)/(CameraLookVector.Magnitude * HeadLookVector.Magnitude)))
local CameraLookVector = RotateTo.Position
local HeadLookVector = plr.Character[WeaponName].Barrel.Position
The script fails because the variables aren’t what the names suggest they are at all. Neither of these are look vectors, or even relative to anything. They are both absolute positions in the world. Your script is trying to find the angle between RotateTo, the center of the world (0, 0, 0) and a gun’s barrel, which will give you nonsense regardless of what you do with them.
Garbage data in, garbage data out.
the angle between your torso and a flying brick
By “the torso” I assume you mean the front facing of the torso.
So the torso direction would be torso.LookVector. It is a vector that points in the same direction as the front surface of the torso, and has a length of 1.
And the flying brick’s position would have to be relative to the torso’s position just like that lookvector, otherwise it will be nonsense. That’s brick.Position - torso.Position. It has an unknown length, but the part with the Magnitudes at the end fixes it up anyway.
local TorsoFacing = Torso.LookVector
local HeadLookVector = plr.Character[WeaponName].Barrel.Position - Torso.Position
You also have to eliminate the y axis of these, so that you don’t get the torso rotating more than normal if the object is high above or low below the torso’s position.
Otherwise it tries measuring the angle between the objects - which isn’t always horizontal - and then rotates the torzo horizontally (i.e. not on the same axis)
local TorsoFacing = Torso.LookVector * Vector3.new(1, 0, 1)
local HeadLookVector = plr.Character[WeaponName].Barrel.Position - Torso.Position * Vector3.new(1, 0, 1)