# Create new vector 10 degrees away from other vector

Hi! I am trying to create an algoritm that calculates a new vector c when the angle between vector a and b is more than 10 degrees. I want the vector c to be exactly 10 degrees away from vector a. Any ideas how to script this?

``````local a = CFrame.new(script.Parent.Position,lastTarget).LookVector
local b = CFrame.new(script.Parent.Position,target).LookVector
local angle = math.acos(a:Dot(b)/(a.Magnitude*b.Magnitude))
if math.deg(angle) > 10 then
local c = -- ???
end
``````

Also, when using math.acos() I only get positive angles. How would I obtain negative angles as well?

If you take the cross product of `a` and `b`, you will get a vector which you can then rotate `a` about (by 10 degrees).

1 Like

You mean to rotate the cross product 10 degrees relative to a? Could you show me how to do that?

No, `a:Cross(b)` will give you the vector to rotate `a` about. You can Rodriguesâ€™ rotation formula to rotate the vector `a` about the vector `a:Cross(b)`. (Following the variable names: `e = a:Cross(b).Unit, v = a`)

1 Like

I wrote up an example here: local v1 = Vector3.new(10, 3, 5)local v2 = Vector3.new(-4, 3, 5)local e = - Pastebin.com where the red part represents v1 and the green part represents v2

2 Likes

Thank you so much for spending so much time on this! It took me some time to understand it, but it solved my problem!