local v1 = vector3(1, 0, 0)
print("v1",vmath.length(v1)) -- 1
local v2 = vector3(1, 0, 1)
print("v2", vmath.length(v2)) -- 1.4142135381699
vmath functions should ignore z position if physics set to 2d mode.
We can’t get/set sprite position. Therefore we forced to maintain draw order using game object z- position. This is source of bugs and confusion because math functions still use z in calculations.
Ok. Then this is design bug. In 2d games I expect length of vector stay the same, no matter of it z component value. We use z for z-ordering, not positioning.
No. Not a bug. The setting you have in game.project for 2D or 3D physics is not what decides if your game is 2D or 3D and it should in no way affect how vector math calculations are carried out on a vector3. If you need to calculate the length of a vector3 with no regard for the z-component you need to write that function yourself.
No. Each sprite you place is positioned in a 3 dimensional space. The thing that makes it 2d is the orthogonal projection that is used in the default render script. Change the projection, or the position and orientation of the camera and the 3d position becomes apparent.
Even if you are creating a 2D game it doesn’t mean that you at all cases want to only use 2d vectors.
We are creating a 2D game right now and I still am using the length function many times within the code. A math lib must be mathematically correct, not context correct.
A vector doesn’t always have to be about transformations either. What if I would like a directional 3d vector in a 3d perlin noise to change a shader? That would be even weirder that I cannot do it just because I set physics to 2D mode (which I might not even use). There are so many other ways they are used.