I want to convert a Vector3 to a vector2 by removing one of the components.
For an array i would use array.remove(axis)
, however no such function exists for Vector3.
I know that Vector3 and vector2 do support other array like assignments: vector3[axis] = 1
The code that i am using now:
func get_vector2_from_vector3(vector3, axis):
var vector2= Vector2(0,0)
var i = 0
var j = 0
while i < 2:
if j == axis:
j += 1
else:
vector2[i] = vector3[j]
i += 1
j += 1
return vector2
and
if (axis == 0):
var vec2 = Vector2(vec3.y, vec3.z)
elif (axis == 1):
var vec2 = Vector2(vec3.x, vec3.z)
elif (axis == 2):
var vec2 = Vector2(vec3.x, vec3.y)
Is there simpler code for this? (preferably without loop or repetition of similar code)
If this is impossible, then i would like to know that as well
I use this and the opposite (Vector2 -> Vector3) a lot, so any simpler code is welkom :)