



Reply From: 
thirite 
So I figured it out, I guess. Relying on get_rotation().y is a bad idea. Will elaborate if I get the time.
I work with Y axis in my FPS game. But it doesn’t matter for me because my object rotates only its Y axis. I use Transform.looking_at()
and use the Z axis, which is alway [x,0,z]. Then, thank to Vector2(1,0).angle_to(Vector2(x,z))
, I get my angle, even if the get_rotate()
goes crazy like you saw by yourself. I wish there was a better way to do it, but at least it works.
Gokudomatic2  20160425 07:29
Have you had time since April to elaborate? I would like to know as well what you found, as I struggle to understand the concept. I just need to know the rotation around the Y axis.
mydoghasworms  20170104 14:44
Hello, I would also be interested in an elaboration if possible. I need to rotate a camera on x and y axis to match a rotation, but stay upright. Were you able to correct the strange Vector3 rotation you were getting?
yepbear  20170107 19:23
Sorry for the late reply. I did work on all this stuff since then. And alas I didn’t found any better solution.
To rotate a camera to face a point while still having Y up, Transform.looking_at(target,Vector3(0,1,0))
works very well.
Edit:
In fact, I just checked my code and I found another way to get Y angle, which might be a little bit faster:
var angle=(v1 * Vector3(1,0,1)).angle_to(v2 * Vector3(1,0,1))
If you cache Vector3(1,0,1)
in a constant, it should be faster than creating 2d vectors while calling getters from 3d vectors in a script. Alas I couldn’t measure it.
And if you don’t want to compare a vector to another but just want to know the angle relative to the vector of reference (which is always at 0°. I usually use the Z axis), you can cache this vector too. For instance, if Z is the reference vector, you can write:
var angle=Vector3(0,0,1).angle_to(my_vector * Vector3(1,0,1))
Gokudomatic2  20170107 19:41
Thanks for replying, this will be very helpful!
yepbear  20170107 21:10
You’re welcome. But I already noticed some difference with the new way. Looks like the angle is always positive, where the angle_to of the 2d vector can be negative. Or something like that, because my code with the new version turns always to the same direction.
Gokudomatic2  20170107 21:20