• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Java atan2 problem

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
Well I have this glorious problem that my atan2 call in Java is acting up like little baby.

The situtation: We have a little game "window"/"lib" made up for us, and we are modifying/adding stuff to it for our class.

Now I have to program a helicopter that will run behind player, and no no collision checks are required(so no pathfinding either).
Everyone I know did it the naive (if Helli X < Player X) Helli X++; the same for Y. But this is shite.

I tried multiple times(past half hour) to tinker with atan2 in Java, and to no avail.

The problem isnt that Im stupid ass. The problem is that the coordinate system works in this way:

You have a rectangle area where you are placed when the game loads up, and the X axis is fine(-x ... 0 ... x), but Y axis is flipped, so it doesnt grow when going up, but it grows when going down
( 0
Y
)

And the atan2 is fucking up hard time(helli will only move in one axis if you are in third or first quadrant, the second one is a bit questionable, and it wont move at all if you are in fourth[by that I mean below it and to the right]).

Is there any way to make atan2 work or to convert the coords in any way to make it work?(I tried the obvious, negate the Y values, but that creates a some weird ass shit)
 
So you're using atan2 to get the orientation of the helicopter to the player?

You already tried negating the Y values, so I recommend writing down on paper what you'd expect the orientations to be and then compare that to the printed result of atan2. Sometimes there can be issues in logic if it returns, for example, an angle on (-pi, pi) vs. (0, 2*pi).

You can also try swapping the coordinates in your atan2, or swap the order of subtraction. The bug is probably somewhere in how you interpret atan2. I'm pretty sure negating the y value should at least lead to a correct result (I doubt there is a bug in atan2).
 
How did you negate the Y axis? you should only negate the Y-axis upon drawing (and invert orther factors for calculations like gravity instead) or create your won draw class that place the coordinates on the desired place. What exactly do you want to use atan2 for? Do you have any sample data to check if atan2 returns the correct answer as expected?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
Ive solved it already by the idiotic(but apparently correct according to what they expect[from unit tests]) approach, which is basically "if my X is smaller than player's, ++x" and the same for y, but thanks for your time
 
Status
Not open for further replies.
Top