Hello, could you tell me how I can get an angle between two vectors?
I’m making a rotation system with HingeContraint.TargetAngle. And I wanted to know the angle from the starting position, and the mouse position.
I wanted the HingeConstraint to rotate my part to the mouse direction
I don’t know if this mapping is right, I based it on what I had researching
1 Like
KJry_s
(MalleoZephyris)
March 26, 2022, 4:09pm
#2
Read these 2 articles:
For my NPC system, I’m looking to have the NPC rotate their head to look at you (obviously with rotation limits). The desired effect will look something like this:
To rotate the head, I use tween service. In the example above, I did:
CFrame = head.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(45))
My question is, what’s the easiest way to get the angle required for the NPC to look at the player?
CFrame = head.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(θ))
[image]
I could …
[image]
I’m trying to find the angle between these two angles. Does anyone have an idea about what to use? I’ve been thinking about using Vector3:Cross() or Vector3:Dot() but I don’t know which one to use I guess. Or maybe CFrame?
fyi |vector|
means the distance of the vectors itself.
we use dot product
angle = math.acos(v1:Dot(v1) / (v1.Magnitude * v2.Magnitude))
I printed this, the printed value is not even more than 1.5
my bad I wrote it incorrectlly dot product of same two vectors isnt logical, it should be:
angle = math.acos(v1:Dot(v2) / (v1.Magnitude * v2.Magnitude))
and also please keep in mind u are getting the angle in radians.
1 Like
system
(system)
Closed
May 7, 2023, 5:13pm
#6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.