Why using CrossProduct.Magnitude instead of Z doesn't work at all

I don’t know if this will help anyone, or if everyone already knows this, but here it is.

I was wondering why we are using CrossProduct.Z instead of the magnitude of the CrossProduct :
CrossProduct(a, b).Size()

I actually used the magnitude in the challenge, and according to the cross product diagram it should have the same results (except from the fact that the tank would always turn right, because magnitude would always be positive):

To my surprise, while using Z worked fine, using magnitude got the AI tanks spinning out of control. It didn’t make any sense. If the vector points up, Z and magnitude should be identical, but they are not. And that’s because the plane that a and b form is not parallel to the ground as in the diagram.

I DebugDrawed the 3 vectors, blue = tank direction, red = intended direction, purple = cross product. The velocity vector that UE gives us is not parallel to the ground, is looking forward and up in a 45° angle (I think), I assume to handle up-hill movements better.

That means that if a and b are looking in the same or opposite direction, they generate a plane perpendicular to the ground, like two dudes moving a glass panel across the street. So the cross product points exactly to the side of the tank, which means that has no elevation, which means that its Z is 0, despite actually having a magnitude.

If they are not looking in the same or opposite direction, they generate a diagonal plane, and the cross product is also diagonal, forming a ‘V’ in relation to that plane:

CrossProduct.Z is not 0 (because the vector is pointing diagonally up), so the tank will keep turning until it is.

If we use magnitude instead of Z, the tank will keep spinning after reaching the desired direction, as the magnitude isn’t 0 in the desired position (although Z is 0), and it never will be, because the desired vector (a) and the actual direction vector (b) will never point in the same direction.

That’s why CrossProduct.Z works and CrossProduct.Magnitude doesn’t work at all. I hope this helps someone.

2 Likes

Privacy & Terms