![]() |
|
ending location from angle and speed - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: ending location from angle and speed (/thread-1600.html) |
ending location from angle and speed - Kazooless - Mar 18, 2009 03:56 AM I'm trying to calculate the ending x,y of my object. I have the starting x,y and the angle in radians and the speed this is what I'm trying: Code: deltaX = cos( rotation ) * speed;the result is almost as if everything is wildly exagerated. does anyone know how to calculate this correctly? ending location from angle and speed - ThemsAllTook - Mar 18, 2009 06:07 AM Seems like you'd want to add deltaX/Y to startingX/Y instead of multiplying them together. ending location from angle and speed - Ingemar - Mar 26, 2009 02:18 AM Also, why multiply the *speed* by cos and sin of the angle? What are you trying to do there? Should the translation be affected by rotation? I usually express this kind of things by matrix multiplication. It scales better to more complex situations. ending location from angle and speed - kendric - Mar 30, 2009 10:52 AM I have a facing vector instead of a facing angle. The plus side is you don't need to cos and sin constantly, only when they turn. Then when you want to move somebody you just do movement=[facing scale:speed]; [position add:movement]; I just made up arbitrary function names but you can probably get the point. When you want to turn all you need to do is rotate the facing vector by X radians negative for a left turn, positive for a right turn. You can rotate a vector using CGAffineTransform functions. ending location from angle and speed - masdest - Mar 30, 2009 07:27 PM Kazooless Wrote:I'm trying to calculate the ending x,y of my object. I have the starting x,y and the angle in radians and the speed I assume this is so that you can move an object on an angle? if so you can use the following code Code: deltaY = sin (rotation) * speed; //this finds the y travel distanceIt's basic trigonometry where the speed is the hypoteneuse and the y is "Opposite" and x is "Adjacent". looking at a clock 3 o'clock would be 0 (or 360) degree, 12 - 90 (or -270) degrees, 9 - 180 (or -180) degrees, 6 - 270 (or -90) degrees. speed * cos (rotation) ending location from angle and speed - Gillissie - Apr 3, 2009 02:40 PM masdest Wrote:I assume this is so that you can move an object on an angle? if so you can use the following code That last line should read: Code: finalX = startingX + deltaX; |