Correcting projectile angles for iso game
by Aaron Miller · in Torque Game Builder · 02/08/2008 (11:32 am) · 6 replies
Hello. My isometric space shooter has a problem with shots fired at certain angles. Angles that correspond to up, down, left and right (0, 90, 180 and 270 degrees) work fine, but any others are slightly off.
Here's the ship firing with an overlaid indicator showing all the directions it should be firing.

The camera elevation is 45 degrees and the ship turns in 15 degree increments. Shots should travel along each indicator, but as you can see they're slightly in between.
I think the problem is that I'm not converting the angle of the shots with respect to the orthographic projection I'm trying to fake. Is anyone math savvy enough to suggest how I might do this so I can feed setRotation the proper angle when I clone shots?
Thanks in advance!
Here's the ship firing with an overlaid indicator showing all the directions it should be firing.

The camera elevation is 45 degrees and the ship turns in 15 degree increments. Shots should travel along each indicator, but as you can see they're slightly in between.
I think the problem is that I'm not converting the angle of the shots with respect to the orthographic projection I'm trying to fake. Is anyone math savvy enough to suggest how I might do this so I can feed setRotation the proper angle when I clone shots?
Thanks in advance!
#2
02/09/2008 (9:19 am)
Thanks Lance. I threw this into Excel and tested a couple of results but I don't think I understand the last step. After you have a modified sine component how do you turn the two components back into an angle?
#3
first, get the vector of your shot direction as if you were looking straight-on.
ie, perfect 15, 30, 45 etc degree vectors, like the green segments in your picture.
then scale the vertical component of the vector by the cosine of your projection angle, which in this case is 45 degrees, so sqrt(2) / 2 = ~.7071.
that vector is the projected version of the shot.
to illustrate, here's a pic where i took your green shots (perfect 15-degree vectors),
put them all in a separate image layer, and then scaled the layer by .71 vertically:
02/09/2008 (9:32 am)
I think another way of saying what Lance is suggesting is:first, get the vector of your shot direction as if you were looking straight-on.
ie, perfect 15, 30, 45 etc degree vectors, like the green segments in your picture.
then scale the vertical component of the vector by the cosine of your projection angle, which in this case is 45 degrees, so sqrt(2) / 2 = ~.7071.
that vector is the projected version of the shot.
to illustrate, here's a pic where i took your green shots (perfect 15-degree vectors),
put them all in a separate image layer, and then scaled the layer by .71 vertically:
#4
i highly recommend sticking w/ vectors whereever possible and avoiding angles,
but if you really want to convert back to an angle,
the formula is theta = arctan(Y / X),
which is commonly implemented via arctan2.
check out this resource for example.
02/09/2008 (9:36 am)
Hey aaron -i highly recommend sticking w/ vectors whereever possible and avoiding angles,
but if you really want to convert back to an angle,
the formula is theta = arctan(Y / X),
which is commonly implemented via arctan2.
check out this resource for example.
#5
Bob's your uncle.
02/09/2008 (3:15 pm)
%vector = mCos(%angle) SPC mSin(%angle); %vector.x *= mSqrt(2) / 2; %angle = mAtan(%vector.y, %vector.x);
Bob's your uncle.
#6
02/13/2008 (5:27 pm)
Lance, Orion, Phillip, thanks a million, it works perfectly!
Torque 3D Owner Lance Hampton
Since you only have a few angles, you could do it in something like excel and make a lookup table.