The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

I'm trying to calculate the angle between my characters Z axis and the cameras Z axis. How would I go about doing this, and does Godot have any build in methods to make it any easier?

in Engine by (274 points)

EDIT: For Vector2 is angle_to, but z axis?

If is for Vector3, just checked and Vector3.angle_to is on Godot 2.1.1

It appears on internal editor's docs (with no details) but are not on the website yet.

Reminder: in Godot, the Camera's Z axis is backwards due to OpenGL convention.
I would go for eons solution once you have the two vectors.
And indeed... the function exists
But it's not in the docs :|

On Godot 4 the object Vector2 provide the method angletopoint(Vector2). Objects based in Node2D provide transform properties like position property, for situate the Node2D, wich is a Vector2 and you can get angle respect to another position (vector2). The result angle (in radians) is necesary to normalize so that fit with the expected, for example adding 180 grades:

self.rotation = self.position.angle_to_point(forwardPosition);
self.rotation_degrees = self.rotation_degrees + 180; #optional, for fit

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.