🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

An angular problem-seems easy but is complex

Started by
0 comments, last by VECTOR 23 years, 11 months ago
In my game I have a ship that gets a 3d destination. Now the ship needs to find the angle on yaxis that it needs to get to to face the target. That''s good. I figured out out that. The x-angle gives me the problem though. I need the destination to be rotated on Y axis (in a temporary variable) so its'' y axis rotation value becomes zero, so that when I check for the x angle it won''t be rotated funny. Being rotated on the Y axis in any direction would affect the xangle that I would find, which is bad. I have come to this solution but I think there must be a better or easier way. Please post the easiest way if you want. ** btw Z axis is not involved. I find the angle on the y axis that it is located in relation to the ship. Say that''s a 45 degree angle. I then rotate it 270 degrees to bring it to zero. That gets rid of anything that might affect the X angle. I suppose that the problem comes all the way down to the easiest way to rotate a 3d point. I suppose this is a pretty long post for such a seemingly small question, but if anybody thinks of an idea I''d like to know of a easier way to do all this.
The object of war is not to die for your country, but to make the other bastard die for his . . -General MacArthur
Advertisement
I assume you''re using trig to calculate the values.

Let (x,y,z) be the direction vector.

Your y calculation might look like

y_angle = atan(y / z); // Opposite over adjacent.

But the length to the destination is no longer [x] when you''ve rotated, so calculate it again.

The new length: new_length = sqrt((y*y) + (z*z));

Only now do we use [x]:

x_angle = atan(x / new_length);

That''s just theory, but I hope you understand it.



========
Smidge
smidge@smidge-tech.co.uk
========
--Mr Smidge

This topic is closed to new replies.

Advertisement