Vector.Rotate() ?

Sorry, but is this function broken? I was using it earlier, but for some reason, it just entirely fails at what it seems to be intended to do.

I’ve been giving a vector an angle to rotate, but for some reason it gives an entirely unreasonable result. The following code seemed to work in one direction, but when rotated past -90 or +90 (to something like -135 or + 135) on the yaw angle, it just flat out broke. Started spitting out insane results. I’d give it a 30 degree angle to rotate around, and it would rotate by a miniscule amount. It would also jump around randomly, for no apparent reason. To sum this up in code…

This code is broken. I had assumed it would work just like the second piece of code.


But it doesn’t seem to?

local InitialLength = VectorToBeRotated:Length()
local InitialAngle = VectorToBeRotated:Angle()
local FinalVector = ((InitialAngle + AngleDifference):Forward()) * InitialLength

So, my question is, is this just borked? If so, is there a better way of rotating the angle than what I’m using? Or rather, since I know there is, can someone point me to the math behind it?

Perhaps you could use Angle.RotateAroundAxis() and then convert that to a vector instead?

That’s essentially what I’m doing by just adding the angle and going Angle:Forward(). I’m not actually convinced that there is a better way of doing this, at this point. I’m just curious as to why Vector.Rotate screws up for me.

Hey, resurrecting this thread to see if anyone has any idea. My way works fine, I’m just curious if vector.Rotate is actually broken.

Maybe it’s just not doing what you expect it to? I could be wrong but I believe it rotates around the origin, so Vector(0,0,0).

Vector:Rotate() doesn’t make much sense anyway because you don’t really know in which order it’s being rotated, and how exactly. You’d better convert your vector to an angle, perform Angle:RotateAroundAxis() on it, and then get the vector back using Angle:Forward(). This way you know exactly what you’re doing, and what the resulting vector will be.