I'm making a flash game in which players throw projectiles to each other - these projectiles have horizontal and vertical speeds: hspeed and vspeed, an x and y coordinate, and set gravity and friction. The motion of the object is updated each frame with this simple code:

Code: Select all

`vspeed += GRAVITY;`

x += hspeed;

y += vspeed;

hspeed *= LINEAR_DAMPING;

vspeed *= LINEAR_DAMPING;

Now for the computer-controlled enemy, I wish to be able to calculate the landing spot of a thrown projectile. Right now, I'm doing this with a function that 'simulates' the movement of a projectile. However, I'd like this to be one simple math function, like x = hspeed*friction^n etc.

So far, I've come up with these functions:

Code: Select all

`x(0) = xstart`

x(n) = xstart + hspeed * sum(LINEAR_DAMPING^(n-1))

y(0) = ystart

y(n) = ystart + (y(n-1)*LINEAR_DAMPING + GRAVITY)

I've also come up with a non-recursive function for y, but I'm not sure if it was correct so I decided not to post it here.

My main question is - is there any way to make these function non-recursive, and not have any sum in it?

Can I rewrite

Code: Select all

`LINEAR_DAMPING^0 .. LINEAR_DAMPING^n`

to anything 'direct' ?

In the end, I'll need something like y = ..x..

so I can calculate the y coordinate just by having the x coordinate. I could really use a push in the right direction. My maths knowledge isn't THAT bad, but I just can't get on with this..

Thanks!