I'm trying to get a vector to "bounce" using an incoming vector and a normal vector. In this case, I am using the muzzleVector of an image for %vector and a normal retrieved from an earlier raycast for %normal.
function getBounceVector(%vector, %normal)
{
%v = %vector;
%n = %normal;
%reflectVec = vectorAdd(vectorCross(vectorCross(vectorDot(%v, %n), %n), -2), %v);
return %reflectVec;
}
I'm not very good at vector math. This seems to work, but for some reason, will only reflect on surfaces facing up, down, north and south. For west and east facing surfaces, %reflectVec ends up being equal to %vector, as if it was just penetrating straight through the surface.