How would I get an atom's true direction using pixel movement? The code I was using for it does not work anymore (it functions properly, but when you step into the same tile as your target, it bugs up and defaults to EAST). Take a look at that code here.
Regards.
FKI wrote:
when you step into the same tile as your target I missed this bit earlier. The reason that it bugs out and defaults to east, is because atan2 can't handle 0 , 0. FIREKing's stuff is all meant for tile-based games only. You need to add the pixel step offsets into his distance formula in order to get the proper coordinates to test against. Lemme convert his stuff over to pixel movement enabled stuff real fast: #define TILE_WIDTH 32 //make sure to set these to your icon width/height |
Getting the x/y delta between two objects:
Converting that into linear distance using the distance formula:
var/d = sqrt(dx**2 + dy**2)
Calculating Sine, and Cosine, and Tangent:
"Opposite" = Delta Y
"Adjacent" = Delta X
"Hypotenuse" = sqrt(Delta X**2 + Delta Y**2)
Sine = Opposite / Hypotenuse
Cosine = Adjacent / Hypotenuse
Tangent = Opposite / Adjacent
Remember: Do you even SOH-CAH-TOA, Bro?
Getting the degree value of sine/cosine:
Getting the angle between two points:
Where:
Check out this post for some decent and fairly optimized functions for you to use:
http://www.byond.com/forum/?post=1289853#comment4842721