Blastfrog Posted July 22, 2018 Just trying to derive an angle and speed from the player's X and Y velocities. Here is the vomit code that I have so far: { airangle = atan2(Vel.Y - 0.0, Vel.X - 0.0); if(Vel.X <= 0) { let lame_a = Vel.X; } else { let lame_a = Vel.X * -1.0; } if(Vel.Y <= 0) { let lame_b = Vel.Y; } else { let lame_b = Vel.Y * -1.0; } let lame_c = sqrt(lame_a + lame_b); } 0 Share this post Link to post
0 fraggle Posted July 22, 2018 You're doing the Pythagorean theorem wrong. It's supposed to be the sum of the square of the velocities. If you do that then you don't need either of the if blocks, since the square of any real number is always positive. let lame_c = sqrt(Vel.X * Vel.X + Vel.Y * Vel.Y); 3 Share this post Link to post
0 Blastfrog Posted July 22, 2018 Thanks, I figured the extra steps weren't necessary, but I've been unable to think clearly at all recently... It just occurred to me that I should've specified what my problem actually is. I'm trying to record the raw speed and direction of the player for the current tic, but I must be using atan2 incorrectly, because it seems to only ever result as 0, which is east. 0 Share this post Link to post
0 Gez Posted July 22, 2018 (edited) I don't understand why you subtract 0.0. It doesn't seem like it should be needed. airangle = atan2(Vel.Y, Vel.X); Ought to work just as well. (Or just as poorly, I guess.) Also this thread should have been titled "Whispers of Atan2" IMO. 0 Share this post Link to post
Just trying to derive an angle and speed from the player's X and Y velocities. Here is the vomit code that I have so far:
Share this post
Link to post