Create Vector3 from angle

Godot Version

4.4

Question

hi everyone

i am creating a tree generator and in my code i want to create a Vector3 with a angle in radian
here is my function

func getVectorFromAngle(angle: Vector3) -> Vector3:
	if angle.length_squared() == 0:
		return Vector3.UP
	else:
		return Vector3.UP.rotated(angle.normalized(), angle.length())

the verification is because Vector3.ZERO.normalized() = Vector3.ZERO

my problem is when i give 2.373648, 1.954769, 3.141593 in radians or 136, 112, 180 in degrees my function return 0.99398, -0.051876, -0.096506 this is realy close to 1, 0, 0 and 136, 112, 180 ist not 1, 0, 0 please help me

What if you just round the output vector like with snappedf?

what do you mean

If it’s very close to the vector you want, but just slightly off, you can snap it to the vector you want.

not it’s not what i want, the vector (1, 0, 0) is not the solution, the solution is -0.62456, 0.728653, 0.281052

i want to have a function who take a angle and return a vector pointing into this direction

But your function takes in a Vector3, not a float angle. I am not sure what Vector3 you want as an output then.

i take in a Vector3 and not a angle because i work in 3D and one angle is not enough

How about Basis.from_euler()? It seems like kind of a roundabout way because you would have to create a basis just to get its rotation but I think it’s the only built in method that does what you want

But your argument for angle is actually the length of the angle. I don’t know how that will result in the Vector3 you want.

the basis sound gut i want a Vector and i don’t know how the basis could help.

Maybe use quaternions? You’re kind of half reinventing them here.

The z property should contain the rotated vector you would expect

i think it’s working. thanks