![]() Now the reason I was using(or misusing) atan2 was because it was suggested to me by someone else, but thats besides the point. And I assumed tbhe way to do this was somehow through the vector: What I want, is to be able to figure out the angle I needed in order to move the player toewards the destination which he clicked on. Ignore the atan2() for a minute, what I want is to be able to move the player by only providing the angle, which works fine with the previous code(excluding atan2()) if I type in the angle manually(given the x and y may be inversed or whatever, doesnt reall matter). Let me be more clear with what I'm trying to do. If that's what you're after, just subtract// the start point from the end point, normalize, and scale by SPEED (I// think this was already mentioned earlier in the thread). Take a look at this example: // Get the vector from player to enemy. In 2D gaming, you often use unit vectors along with multipliers to calculate a projectile's vector based on the speed you want it to travel at. I'm not sure// if that has anything to do with your problem, but I thought I'd mention it.angle = atan2(vector.x, vector.y) // At this point, 'angle' is in radians.radians = PI / 180 * angle // Now it's.um.some meaningless value? It looks like you're converting// to radians a value that's already in radians.// In other words, try ditching the 'radians' variable, and just replace// 'radians' with 'angle' in the following two -= sin(radians) * SPEED position.y += cos(radians) * SPEED // That said, there's little point in computing an angle using atan2(),// and then turning around and computing a (possibly scaled) normalized// vector using sin() and cos(). y cos (r) Both code blocks above will give you the same unit vector. Anyone, please?I didn't read the thread that carefully, but I did notice a couple of things: // Typically you would want (y,x) here rather than (x,y).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |