View Single Post
  #2 (permalink)  
Old 11-27-2009, 02:52 AM
Fubarable's Avatar
Fubarable Fubarable is online now
Moderator
 
Join Date: Jun 2008
Posts: 6,502
Rep Power: 8
Fubarable is on a distinguished road
Default
So xSpeed and xPos are easy to deal with since xSpeed is a constant and doesn't change with time.

ySpeed however changes continuously with time under the influence of gravity, and this will have to be dealt with. First your equation:

ySpeed = V * sin(A)

This only defines y's starting speed, that's it, and so you can only use this equation at the beginning of your calculations. Perhaps you should think of V * sin(A) as ySpeed0. So to do this correctly, you'd have this equation before the loop. something like so:

Code:
// pseudocode

double xSpeed = v * cos(angle)
double ySpeed = v * sin(angle)

loop incrementing time {
   xPos = xPos + xSpeed * time;
   yPos = yPos + ySpeed * time;

   ySpeed = ySpeed - gravity * time;
}
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Reply With Quote