Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Angle the nextHrp is based on the hrp's LookVector
- local function XZAngleToNextHrp(hrp, nextHrp)
- -- Vector pointing in the direction of the nextHrp of length 1
- local dir = (nextHrp.Position - hrp.Position).Unit
- -- We only want to find the angle to the right or left, not up and down
- -- Get rid of the Y value
- local vecA = Vector2.new(dir.X, dir.Z)
- local vecB = Vector2.new(hrp.CFrame.LookVector.X, hrp.CFrame.LookVector.Z)
- -- Dot product is used to find the angle between lookVec and dir
- local dotValue = vecA:Dot(vecB)
- -- Cross product creates another vector used to orient the +/- of the angle
- local crossValue = vecA:Cross(vecB)
- -- with the dot product and cross product, atan2 find the angle you need
- local angle = math.atan2(crossValue, dotValue)
- return angle
- end
Add Comment
Please, Sign In to add comment