Re: [pygame] trajectory

2011-07-25 Thread BIAGINI Nathan
Thanks.

The TD i have planned to code may contain lot of direction changes so i think i 
will use homing missile, i have already started to code a kind of homing 
missile firing system using vector thanks to numpy and it s not too bad.

Le 25 juil. 2011 à 06:07, Jake b ninmonk...@gmail.com a écrit

 This calculates to shoot in the path of the target. 
 Like how you throw a football, to lead the catcher. Instead of where they are 
 at that second.  
 
 For tower defense, some Bullets fly fast enough you don't have to lead. 
 
 Slower bullets fire, then every frame you:
 Move the bullet location toward target. ( without leading )
 Thats simple homing, but you can skip the steering part a homing missile has. 
 The trajectory will end up curving, depending on speeds used. 
 
 For a straight line you will have to lead. But leading will miss if target 
 chamges direction or speed. 
 
 On Saturday, July 23, 2011, Joe Ranalli jrana...@gmail.com wrote:
  Yes. 
 
  So to be more explicit:
 
  1 Calculate the distance between the source and the target.
  2 Calculate the time for the bullet to move that distance (i.e. by dividing 
  this distance by the bullet velocity)
  3 Calculate newposition (multiply the target velocity by the time 
  calculated in the previous step, add to original target position)
  1a Recalculate the distance between the source and newposition
  2a Recalculate the time for the bullet to move from the source to 
  newposition (i.e. divide the new distance by the bullet velocity)
  3a Recalculate newposition using this new time (multiply the target 
  velocity by the new time calculated in the previous step, add to original 
  target position)
 
 
 
  On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI nathan.o...@gmail.com 
  wrote:
 
  Ok so thanks all for all your replies i will work with all that. I don't 
  know already if i want to use homing missile style which seems to be 
  easier to code or to use an algorithm to fire straight to the right spot.
  To be honest, i'm not native english speaker and it's not always easy to 
  figure out what you really mean but i'm doing my best.
 
  I just want to ask you Joe about your algorithm :
 
  If you want to have the bullet go straight to the right spot, you need to:
  1) calculate how long the bullet will take to get to the enemy
  2) calculate where the enemy will be at that time (newposition)
  3) calculate how long it will take the bullet to get to newposition
  4) recalculate newposition based on the new time
 
  Ok so i think the first step is pretty clear to me, the step 2 too but i 
  don't understand the step 3. My english isn't the best i repeat so... i 
  have to calculate how long the bullet will take to go to 'newposition'. So 
  i will get a new time value and then i need to recalculate newposition 
  based on this new time? And fire at 'newposition'? And also, to be sure, 
  'newposition' is the virtual position of the target after the time taken 
  by the bullet to hit it, right?
 
  Sorry if it seems to be straigh forward to you :-)
 
  Of course i will try others way like Lee suggested me.
 
  Thanks.
   
  2011/7/20 Joe Ranalli jrana...@gmail.com
 
  It depends what you're trying to do. 
 
  If you draw the straight line between the tower and the enemy and use 
  that vector to translate a bullet each tick, the bullets might miss the 
  enemy.  Think about it this way, the bullet moves 2 steps toward the 
  enemy, then the enemy moves 1 step, then the bullet moves 2, etc.  
  Because the enemy moves the bullet will have to change its direction 
  through the flight.  So you could calculate the direction vector between 
  the bullet and the enemy every tick and have the bullet move that 
  direction.  That would make the bullets kind of arc to the target.
 
  If you want to have the bullet go straight to the right spot, you need to:
  1) calculate how long the bullet will take to get to the enemy
  2) calculate where the enemy will be at that time (newposition)
  3) calculate how long it will take the bullet to get to newposition
  4) recalculate newposition based on the new time
 
  Technically you could iterate that repeatedly until newposition 
  converges.  Practically, iterating once probably gets you close enough 
  unless the movement is extremely complicated.
 
  On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.com 
  wrote:
 
  Hi everyone,
 
  i would like to know what are the common way to handle trajectory in a 
  2d game. In fact, i think of writing a tower defense game and i wonder 
  how to handle the trajectory of the missile launch by the towers. I 
  though of getting the pos of the tower and the target and create a 
  vector between this two entitites to make a sprite translation of this 
  vector but there is maybe some tricky stuff to do it.
 
  Thanks in advance and happy game making all :-)
 
 
 
 
 
 -- 
 Jake


Re: [pygame] trajectory

2011-07-25 Thread inigo.delg...@gmail.com
Im late to this threath but

Why dont recalculate de vector in each iteration?

they are two substractions... not a extensive calculation... no?

This way missile ALWAYS will reach it objetive.

2011/7/25 BIAGINI Nathan nathan.o...@gmail.com:
 Thanks.
 The TD i have planned to code may contain lot of direction changes so i
 think i will use homing missile, i have already started to code a kind of
 homing missile firing system using vector thanks to numpy and it s not too
 bad.

 Le 25 juil. 2011 à 06:07, Jake b ninmonk...@gmail.com a écrit

 This calculates to shoot in the path of the target.
 Like how you throw a football, to lead the catcher. Instead of where they
 are at that second.

 For tower defense, some Bullets fly fast enough you don't have to lead.

 Slower bullets fire, then every frame you:
 Move the bullet location toward target. ( without leading )
 Thats simple homing, but you can skip the steering part a homing missile
 has. The trajectory will end up curving, depending on speeds used.

 For a straight line you will have to lead. But leading will miss if target
 chamges direction or speed.

 On Saturday, July 23, 2011, Joe Ranalli jrana...@gmail.com wrote:
 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)



 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI nathan.o...@gmail.com
 wrote:

 Ok so thanks all for all your replies i will work with all that. I don't
 know already if i want to use homing missile style which seems to be easier
 to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy to
 figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Ok so i think the first step is pretty clear to me, the step 2 too but i
 don't understand the step 3. My english isn't the best i repeat so... i have
 to calculate how long the bullet will take to go to 'newposition'. So i will
 get a new time value and then i need to recalculate newposition based on
 this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.

 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.com
 wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in
 a 2d game. In fact, i think of writing a tower defense game and i wonder 
 how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance 

Re: [pygame] trajectory

2011-07-24 Thread Jake b
This calculates to shoot in the path of the target.
Like how you throw a football, to lead the catcher. Instead of where they
are at that second.

For tower defense, some Bullets fly fast enough you don't have to lead.

Slower bullets fire, then every frame you:
Move the bullet location toward target. ( without leading )
Thats simple homing, but you can skip the steering part a homing missile
has. The trajectory will end up curving, depending on speeds used.

For a straight line you will have to lead. But leading will miss if target
chamges direction or speed.

On Saturday, July 23, 2011, Joe Ranalli jrana...@gmail.com wrote:
 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
velocity by the new time calculated in the previous step, add to original
target position)



 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI nathan.o...@gmail.com
wrote:

 Ok so thanks all for all your replies i will work with all that. I don't
know already if i want to use homing missile style which seems to be easier
to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy to
figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :

 If you want to have the bullet go straight to the right spot, you need
to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Ok so i think the first step is pretty clear to me, the step 2 too but i
don't understand the step 3. My english isn't the best i repeat so... i have
to calculate how long the bullet will take to go to 'newposition'. So i will
get a new time value and then i need to recalculate newposition based on
this new time? And fire at 'newposition'? And also, to be sure,
'newposition' is the virtual position of the target after the time taken by
the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
that vector to translate a bullet each tick, the bullets might miss the
enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
enemy moves the bullet will have to change its direction through the
flight.  So you could calculate the direction vector between the bullet and
the enemy every tick and have the bullet move that direction.  That would
make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
converges.  Practically, iterating once probably gets you close enough
unless the movement is extremely complicated.

 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.com
wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in
a 2d game. In fact, i think of writing a tower defense game and i wonder how
to handle the trajectory of the missile launch by the towers. I though of
getting the pos of the tower and the target and create a vector between this
two entitites to make a sprite translation of this vector but there is maybe
some tricky stuff to do it.

 Thanks in advance and happy game making all :-)





-- 
Jake


Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
Ok so thanks all for all your replies i will work with all that. I don't
know already if i want to use homing missile style which seems to be easier
to code or to use an algorithm to fire straight to the right spot.
To be honest, i'm not native english speaker and it's not always easy to
figure out what you really mean but i'm doing my best.

I just want to ask you Joe about your algorithm :

If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


Ok so i think the first step is pretty clear to me, the step 2 too but i
don't understand the step 3. My english isn't the best i repeat so... i have
to calculate how long the bullet will take to go to 'newposition'. So i will
get a new time value and then i need to recalculate newposition based on
this new time? And fire at 'newposition'? And also, to be sure,
'newposition' is the virtual position of the target after the time taken by
the bullet to hit it, right?

Sorry if it seems to be straigh forward to you :-)

Of course i will try others way like Lee suggested me.

Thanks.

2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use that
 vector to translate a bullet each tick, the bullets might miss the enemy.
 Think about it this way, the bullet moves 2 steps toward the enemy, then the
 enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
 the bullet will have to change its direction through the flight.  So you
 could calculate the direction vector between the bullet and the enemy every
 tick and have the bullet move that direction.  That would make the bullets
 kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition converges.
 Practically, iterating once probably gets you close enough unless the
 movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)





Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it will
works in case of re


Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it will
works in case of really simple tower defense graph, where the target always
progress to a point A to a point B?

2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by dividing
 this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok so thanks all for all your replies i will work with all that. I don't
 know already if i want to use homing missile style which seems to be easier
 to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy to
 figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too but i
 don't understand the step 3. My english isn't the best i repeat so... i have
 to calculate how long the bullet will take to go to 'newposition'. So i will
 get a new time value and then i need to recalculate newposition based on
 this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)







Re: [pygame] trajectory

2011-07-23 Thread Joe Ranalli
Yes, it will work as long as the target doesn't change direction.

On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it will
 works in case of really simple tower defense graph, where the target always
 progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Ok so thanks all for all your replies i will work with all that. I don't
 know already if i want to use homing missile style which seems to be easier
 to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy to
 figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too but i
 don't understand the step 3. My english isn't the best i repeat so... i have
 to calculate how long the bullet will take to go to 'newposition'. So i will
 get a new time value and then i need to recalculate newposition based on
 this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in
 a 2d game. In fact, i think of writing a tower defense game and i wonder 
 how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)








Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
So if the source if moving to the left, get in range of a tower and during
the algorithm progress go up or down, it will not work. That's it?

2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes, it will work as long as the target doesn't change direction.


 On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it will
 works in case of really simple tower defense graph, where the target always
 progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Ok so thanks all for all your replies i will work with all that. I don't
 know already if i want to use homing missile style which seems to be easier
 to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy to
 figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too but i
 don't understand the step 3. My english isn't the best i repeat so... i 
 have
 to calculate how long the bullet will take to go to 'newposition'. So i 
 will
 get a new time value and then i need to recalculate newposition based on
 this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the 
 enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet 
 and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.com
  wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in
 a 2d game. In fact, i think of writing a tower defense game and i wonder 
 how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)









Re: [pygame] trajectory

2011-07-23 Thread Joe Ranalli
You are aiming the bullet based on where you calculate the target will be
when the bullet gets there.  If the target changes direction, your aim is
wrong.

On Sat, Jul 23, 2011 at 1:24 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 So if the source if moving to the left, get in range of a tower and during
 the algorithm progress go up or down, it will not work. That's it?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes, it will work as long as the target doesn't change direction.


 On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it
 will works in case of really simple tower defense graph, where the target
 always progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI nathan.o...@gmail.com
  wrote:

 Ok so thanks all for all your replies i will work with all that. I
 don't know already if i want to use homing missile style which seems to be
 easier to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy
 to figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too but
 i don't understand the step 3. My english isn't the best i repeat so... i
 have to calculate how long the bullet will take to go to 'newposition'. 
 So i
 will get a new time value and then i need to recalculate newposition based
 on this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken 
 by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the 
 enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet 
 and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory
 in a 2d game. In fact, i think of writing a tower defense game and i 
 wonder
 how to handle the trajectory of the missile launch by the towers. I 
 though
 of getting the pos of the tower and the target and create a vector 
 between
 this two entitites to make a sprite translation of this vector but 
 there is
 maybe some tricky stuff to do it.

 Thanks in advance and happy game making all :-)










Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
Yeah but if you calculate the node of the graph where the target will be
when the bullet get there. Can it works?

2011/7/23 Joe Ranalli jrana...@gmail.com

 You are aiming the bullet based on where you calculate the target will be
 when the bullet gets there.  If the target changes direction, your aim is
 wrong.


 On Sat, Jul 23, 2011 at 1:24 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 So if the source if moving to the left, get in range of a tower and during
 the algorithm progress go up or down, it will not work. That's it?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes, it will work as long as the target doesn't change direction.


 On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it
 will works in case of really simple tower defense graph, where the target
 always progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Ok so thanks all for all your replies i will work with all that. I
 don't know already if i want to use homing missile style which seems to 
 be
 easier to code or to use an algorithm to fire straight to the right spot.
 To be honest, i'm not native english speaker and it's not always easy
 to figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too but
 i don't understand the step 3. My english isn't the best i repeat so... i
 have to calculate how long the bullet will take to go to 'newposition'. 
 So i
 will get a new time value and then i need to recalculate newposition 
 based
 on this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time taken 
 by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the 
 enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet 
 and
 the enemy every tick and have the bullet move that direction.  That 
 would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory
 in a 2d game. In fact, i think of writing a tower defense game and i 
 wonder
 how to handle the trajectory of the missile launch by the towers. I 
 though
 of getting the pos of the tower and the target and create a vector 
 between
 this two entitites to make a sprite translation of this vector but 
 there is
 maybe some tricky stuff to do it.

 Thanks in advance and happy game making all :-)











Re: [pygame] trajectory

2011-07-23 Thread Joe Ranalli
Oh, sure.  If you know exactly how the target will move and calculate
newposition based on where the target will be including changes of direction
and everything, then you will be aiming at the right spot.  It still seems
like using the homing bullets would be easier though.

On Sat, Jul 23, 2011 at 1:29 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Yeah but if you calculate the node of the graph where the target will be
 when the bullet get there. Can it works?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 You are aiming the bullet based on where you calculate the target will be
 when the bullet gets there.  If the target changes direction, your aim is
 wrong.


 On Sat, Jul 23, 2011 at 1:24 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 So if the source if moving to the left, get in range of a tower and
 during the algorithm progress go up or down, it will not work. That's it?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes, it will work as long as the target doesn't change direction.


 On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it
 will works in case of really simple tower defense graph, where the target
 always progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Ok so thanks all for all your replies i will work with all that. I
 don't know already if i want to use homing missile style which seems to 
 be
 easier to code or to use an algorithm to fire straight to the right 
 spot.
 To be honest, i'm not native english speaker and it's not always easy
 to figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too
 but i don't understand the step 3. My english isn't the best i repeat 
 so...
 i have to calculate how long the bullet will take to go to 
 'newposition'. So
 i will get a new time value and then i need to recalculate newposition 
 based
 on this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time 
 taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and
 use that vector to translate a bullet each tick, the bullets might 
 miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the 
 enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the 
 bullet and
 the enemy every tick and have the bullet move that direction.  That 
 would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory
 in a 2d game. In fact, i think of writing a tower defense game and i 
 wonder
 how to handle the trajectory of the missile launch by the towers. I 
 though
 of getting the pos of the tower and the target and create 

Re: [pygame] trajectory

2011-07-23 Thread Nathan BIAGINI
Yeah i also think so... and if the bullet is really faster than the target,
it should not be that much visible.

2011/7/23 Joe Ranalli jrana...@gmail.com

 Oh, sure.  If you know exactly how the target will move and calculate
 newposition based on where the target will be including changes of direction
 and everything, then you will be aiming at the right spot.  It still seems
 like using the homing bullets would be easier though.


 On Sat, Jul 23, 2011 at 1:29 PM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Yeah but if you calculate the node of the graph where the target will be
 when the bullet get there. Can it works?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 You are aiming the bullet based on where you calculate the target will be
 when the bullet gets there.  If the target changes direction, your aim is
 wrong.


 On Sat, Jul 23, 2011 at 1:24 PM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 So if the source if moving to the left, get in range of a tower and
 during the algorithm progress go up or down, it will not work. That's it?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes, it will work as long as the target doesn't change direction.


 On Sat, Jul 23, 2011 at 1:13 PM, Nathan BIAGINI nathan.o...@gmail.com
  wrote:

 Ok. Yeah it's more explicit, thanks to take time to rewrite it. So it
 will works in case of really simple tower defense graph, where the target
 always progress to a point A to a point B?


 2011/7/23 Joe Ranalli jrana...@gmail.com

 Yes.

 So to be more explicit:

 1 Calculate the distance between the source and the target.
 2 Calculate the time for the bullet to move that distance (i.e. by
 dividing this distance by the bullet velocity)
 3 Calculate newposition (multiply the target velocity by the time
 calculated in the previous step, add to original target position)
 1a Recalculate the distance between the source and newposition
 2a Recalculate the time for the bullet to move from the source to
 newposition (i.e. divide the new distance by the bullet velocity)
 3a Recalculate newposition using this new time (multiply the target
 velocity by the new time calculated in the previous step, add to 
 original
 target position)




 On Sat, Jul 23, 2011 at 12:55 PM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Ok so thanks all for all your replies i will work with all that. I
 don't know already if i want to use homing missile style which seems 
 to be
 easier to code or to use an algorithm to fire straight to the right 
 spot.
 To be honest, i'm not native english speaker and it's not always
 easy to figure out what you really mean but i'm doing my best.

 I just want to ask you Joe about your algorithm :


  If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time


 Ok so i think the first step is pretty clear to me, the step 2 too
 but i don't understand the step 3. My english isn't the best i repeat 
 so...
 i have to calculate how long the bullet will take to go to 
 'newposition'. So
 i will get a new time value and then i need to recalculate newposition 
 based
 on this new time? And fire at 'newposition'? And also, to be sure,
 'newposition' is the virtual position of the target after the time 
 taken by
 the bullet to hit it, right?

 Sorry if it seems to be straigh forward to you :-)

 Of course i will try others way like Lee suggested me.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and
 use that vector to translate a bullet each tick, the bullets might 
 miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the 
 enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because 
 the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the 
 bullet and
 the enemy every tick and have the bullet move that direction.  That 
 would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you
 need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.com wrote:

 Hi everyone,

 i would like to know what are the common way to handle
 trajectory in a 2d game. In fact, i think of writing a 

Re: [pygame] trajectory

2011-07-22 Thread R. Alan Monroe


 i would like to know what are the common way to handle trajectory in a 2d
 game.

http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html



Re: [pygame] trajectory

2011-07-22 Thread Nathan BIAGINI
Hi. Thanks all for you replies i have one more question before trying to
write something on top of that, your algorithme Joe, does it works if the
way has some bifurcations, i mean, a fully linear way but that contain
bifurcations.

Thanks.

2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use that
 vector to translate a bullet each tick, the bullets might miss the enemy.
 Think about it this way, the bullet moves 2 steps toward the enemy, then the
 enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
 the bullet will have to change its direction through the flight.  So you
 could calculate the direction vector between the bullet and the enemy every
 tick and have the bullet move that direction.  That would make the bullets
 kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition converges.
 Practically, iterating once probably gets you close enough unless the
 movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)





Re: [pygame] trajectory

2011-07-22 Thread Joe Ranalli
I'm not totally clear on what you're asking.  If you're saying that the
targets might change direction after the bullet is fired, but you still want
the bullet to hit the target, then my second algorithm wouldn't work.  That
just doesn't make any sense.  The algorithm I suggested aims at the target,
then shoots at it.  If the target changes direction, then it will no longer
go to the spot you were aiming.

If you're having this much trouble figuring this out I would definitely
suggest you take some time to sit down and think about what it is you're
trying to do and maybe read about some simple physics.  This part of the
application really shouldn't be that difficult to figure out.

On Fri, Jul 22, 2011 at 9:08 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi. Thanks all for you replies i have one more question before trying to
 write something on top of that, your algorithme Joe, does it works if the
 way has some bifurcations, i mean, a fully linear way but that contain
 bifurcations.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use that
 vector to translate a bullet each tick, the bullets might miss the enemy.
 Think about it this way, the bullet moves 2 steps toward the enemy, then the
 enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
 the bullet will have to change its direction through the flight.  So you
 could calculate the direction vector between the bullet and the enemy every
 tick and have the bullet move that direction.  That would make the bullets
 kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)






Re: [pygame] trajectory

2011-07-22 Thread Lee Buckingham
Unless the bullet can change direction in flight, it will have to choose
one, and only one spot to aim for, and therefore, one vector to guide it.
Homing missiles are a lot different to code for, since they have to adjust
course, and potentially deal with a synthesized form of inertia.

A bifurcating tree of solutions seems to suggest looking at all possible
'likely' positions for the target in the future.  That's not so much vector
math as it is statistics and player-psychology.

You also probably don't want to deal with linear solutions to this problem,
unless you really really need pinpoint accuracy on each shot (again,
assuming NOTHING changes direction or speed after a shot is fired, which
makes all that accuracy useless anyway).  Breaking it up into steps that are
a little smaller than the clipping rectangles involved will probably get you
more than close enough.  Furthermore, there will be a different solution to
the linear form of the problem for every firing angle (wide angles intercept
later, etc...) It would get pretty ugly.

It might suit better to 'fudge' in a calculation.  Make an estimated change
(just add a constant or something) to the current position of the target,
based on it's speed and direction, and fire at that position.  Divide the x
and y distance to the target each by the speed of your bullet (you don't
even NEED to do the trigonometry for speed calculations, the player wouldn't
notice much anyway) and make the bullet move that much in the x and y
directions each tick.  Try it out... are your shots firing too far ahead?
Too far behind??   Change the estimation constant a little bit and try
again.  If the target is in close, you might have to reduce the estimate a
bit, etc...   You can probably tweak this one enough to have a very
satisfying firing computer without having to go through the hassle of
reading the physics chapter on ballistics.

Just a few ideas...

-Lee-

On Fri, Jul 22, 2011 at 7:21 AM, Joe Ranalli jrana...@gmail.com wrote:

 I'm not totally clear on what you're asking.  If you're saying that the
 targets might change direction after the bullet is fired, but you still want
 the bullet to hit the target, then my second algorithm wouldn't work.  That
 just doesn't make any sense.  The algorithm I suggested aims at the target,
 then shoots at it.  If the target changes direction, then it will no longer
 go to the spot you were aiming.

 If you're having this much trouble figuring this out I would definitely
 suggest you take some time to sit down and think about what it is you're
 trying to do and maybe read about some simple physics.  This part of the
 application really shouldn't be that difficult to figure out.


 On Fri, Jul 22, 2011 at 9:08 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi. Thanks all for you replies i have one more question before trying to
 write something on top of that, your algorithme Joe, does it works if the
 way has some bifurcations, i mean, a fully linear way but that contain
 bifurcations.

 Thanks.

 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)







Re: [pygame] trajectory

2011-07-22 Thread James Paige
In most (but maybe not all) tower defense games I have ever played, 
bullets *can* change direction in flight, and do behave like homing 
missles. This isn't obvious visually if the bullets are fast, but it is 
pretty common in tower defense games that if a target is in range when 
the bullet is launched that it will always hit the target no matter how 
it moves.

That being said, I don't have any idea if Nathan Biagini wants to make 
his own tower defense game work that way or not :)

---
James Paige


On Fri, Jul 22, 2011 at 08:24:51AM -0700, Lee Buckingham wrote:
Unless the bullet can change direction in flight, it will have to choose
one, and only one spot to aim for, and therefore, one vector to guide it. 
Homing missiles are a lot different to code for, since they have to adjust
course, and potentially deal with a synthesized form of inertia.  
 
A bifurcating tree of solutions seems to suggest looking at all possible
'likely' positions for the target in the future.  That's not so much
vector math as it is statistics and player-psychology.
 
You also probably don't want to deal with linear solutions to this
problem, unless you really really need pinpoint accuracy on each shot
(again, assuming NOTHING changes direction or speed after a shot is fired,
which makes all that accuracy useless anyway).  Breaking it up into steps
that are a little smaller than the clipping rectangles involved will
probably get you more than close enough.  Furthermore, there will be a
different solution to the linear form of the problem for every firing
angle (wide angles intercept later, etc...) It would get pretty ugly.
 
It might suit better to 'fudge' in a calculation.  Make an estimated
change (just add a constant or something) to the current position of the
target, based on it's speed and direction, and fire at that position. 
Divide the x and y distance to the target each by the speed of your bullet
(you don't even NEED to do the trigonometry for speed calculations, the
player wouldn't notice much anyway) and make the bullet move that much in
the x and y directions each tick.  Try it out... are your shots firing too
far ahead?  Too far behind??   Change the estimation constant a little bit
and try again.  If the target is in close, you might have to reduce the
estimate a bit, etc...   You can probably tweak this one enough to have a
very satisfying firing computer without having to go through the hassle
of reading the physics chapter on ballistics.
 
Just a few ideas...
 
-Lee-
 
On Fri, Jul 22, 2011 at 7:21 AM, Joe Ranalli jrana...@gmail.com wrote:
 
  I'm not totally clear on what you're asking.  If you're saying that the
  targets might change direction after the bullet is fired, but you still
  want the bullet to hit the target, then my second algorithm wouldn't
  work.  That just doesn't make any sense.  The algorithm I suggested aims
  at the target, then shoots at it.  If the target changes direction, then
  it will no longer go to the spot you were aiming.
 
  If you're having this much trouble figuring this out I would definitely
  suggest you take some time to sit down and think about what it is you're
  trying to do and maybe read about some simple physics.  This part of the
  application really shouldn't be that difficult to figure out.
 
  On Fri, Jul 22, 2011 at 9:08 AM, Nathan BIAGINI nathan.o...@gmail.com
  wrote:
 
Hi. Thanks all for you replies i have one more question before trying
to write something on top of that, your algorithme Joe, does it works
if the way has some bifurcations, i mean, a fully linear way but that
contain bifurcations.
 
Thanks.
 
2011/7/20 Joe Ranalli jrana...@gmail.com
 
  It depends what you're trying to do. 
 
  If you draw the straight line between the tower and the enemy and
  use that vector to translate a bullet each tick, the bullets might
  miss the enemy.  Think about it this way, the bullet moves 2 steps
  toward the enemy, then the enemy moves 1 step, then the bullet moves
  2, etc.  Because the enemy moves the bullet will have to change its
  direction through the flight.  So you could calculate the direction
  vector between the bullet and the enemy every tick and have the
  bullet move that direction.  That would make the bullets kind of arc
  to the target.
 
  If you want to have the bullet go straight to the right spot, you
  need to:
  1) calculate how long the bullet will take to get to the enemy
  2) calculate where the enemy will be at that time (newposition)
  3) calculate how long it will take the bullet to get to newposition
  4) recalculate newposition based on the new time
 
  Technically you could 

Re: [pygame] trajectory

2011-07-22 Thread Joe Ranalli
Homing missile is by far the easiest thing to code.  Every clock tick, find
the vector between the bullet and the target, move the bullet in that
direction according to its velocity.  As long as the bullet speed is fast
relative to the target, it will eventually hit it.

On Fri, Jul 22, 2011 at 11:56 AM, James Paige b...@hamsterrepublic.comwrote:

 In most (but maybe not all) tower defense games I have ever played,
 bullets *can* change direction in flight, and do behave like homing
 missles. This isn't obvious visually if the bullets are fast, but it is
 pretty common in tower defense games that if a target is in range when
 the bullet is launched that it will always hit the target no matter how
 it moves.

 That being said, I don't have any idea if Nathan Biagini wants to make
 his own tower defense game work that way or not :)

 ---
 James Paige


 On Fri, Jul 22, 2011 at 08:24:51AM -0700, Lee Buckingham wrote:
 Unless the bullet can change direction in flight, it will have to
 choose
 one, and only one spot to aim for, and therefore, one vector to guide
 it.
 Homing missiles are a lot different to code for, since they have to
 adjust
 course, and potentially deal with a synthesized form of inertia.
 
 A bifurcating tree of solutions seems to suggest looking at all
 possible
 'likely' positions for the target in the future.  That's not so much
 vector math as it is statistics and player-psychology.
 
 You also probably don't want to deal with linear solutions to this
 problem, unless you really really need pinpoint accuracy on each shot
 (again, assuming NOTHING changes direction or speed after a shot is
 fired,
 which makes all that accuracy useless anyway).  Breaking it up into
 steps
 that are a little smaller than the clipping rectangles involved will
 probably get you more than close enough.  Furthermore, there will be a
 different solution to the linear form of the problem for every firing
 angle (wide angles intercept later, etc...) It would get pretty ugly.
 
 It might suit better to 'fudge' in a calculation.  Make an estimated
 change (just add a constant or something) to the current position of
 the
 target, based on it's speed and direction, and fire at that position.
 Divide the x and y distance to the target each by the speed of your
 bullet
 (you don't even NEED to do the trigonometry for speed calculations,
 the
 player wouldn't notice much anyway) and make the bullet move that much
 in
 the x and y directions each tick.  Try it out... are your shots firing
 too
 far ahead?  Too far behind??   Change the estimation constant a little
 bit
 and try again.  If the target is in close, you might have to reduce
 the
 estimate a bit, etc...   You can probably tweak this one enough to
 have a
 very satisfying firing computer without having to go through the
 hassle
 of reading the physics chapter on ballistics.
 
 Just a few ideas...
 
 -Lee-
 
 On Fri, Jul 22, 2011 at 7:21 AM, Joe Ranalli jrana...@gmail.com
 wrote:
 
   I'm not totally clear on what you're asking.  If you're saying that
 the
   targets might change direction after the bullet is fired, but you
 still
   want the bullet to hit the target, then my second algorithm wouldn't
   work.  That just doesn't make any sense.  The algorithm I suggested
 aims
   at the target, then shoots at it.  If the target changes direction,
 then
   it will no longer go to the spot you were aiming.
 
   If you're having this much trouble figuring this out I would
 definitely
   suggest you take some time to sit down and think about what it is
 you're
   trying to do and maybe read about some simple physics.  This part of
 the
   application really shouldn't be that difficult to figure out.
 
   On Fri, Jul 22, 2011 at 9:08 AM, Nathan BIAGINI 
 nathan.o...@gmail.com
   wrote:
 
 Hi. Thanks all for you replies i have one more question before
 trying
 to write something on top of that, your algorithme Joe, does it
 works
 if the way has some bifurcations, i mean, a fully linear way but
 that
 contain bifurcations.
 
 Thanks.
 
 2011/7/20 Joe Ranalli jrana...@gmail.com
 
   It depends what you're trying to do.
 
   If you draw the straight line between the tower and the enemy
 and
   use that vector to translate a bullet each tick, the bullets
 might
   miss the enemy.  Think about it this way, the bullet moves 2
 steps
   toward the enemy, then the enemy moves 1 step, then the bullet
 moves
   2, etc.  Because the enemy moves the bullet will have to change
 its
   direction through the flight.  So you could calculate the
 direction
   vector between the bullet and the enemy every tick and have the
   bullet move that direction.  That would make the bullets kind of
 arc
 

Re: [pygame] trajectory

2011-07-22 Thread Jake b
A more involved example, but a great site is red3d's steering movements.
To do heat seeking missiles, you use the seek behavior.
http://www.red3d.com/cwr/steer/

On Fri, Jul 22, 2011 at 11:45 AM, Joe Ranalli jrana...@gmail.com wrote:

 Homing missile is by far the easiest thing to code.  Every clock tick, find
 the vector between the bullet and the target, move the bullet in that
 direction according to its velocity.  As long as the bullet speed is fast
 relative to the target, it will eventually hit it.




-- 
Jake


[pygame] trajectory

2011-07-20 Thread Nathan BIAGINI
Hi everyone,

i would like to know what are the common way to handle trajectory in a 2d
game. In fact, i think of writing a tower defense game and i wonder how to
handle the trajectory of the missile launch by the towers. I though of
getting the pos of the tower and the target and create a vector between this
two entitites to make a sprite translation of this vector but there is maybe
some tricky stuff to do it.

Thanks in advance and happy game making all :-)


Re: [pygame] trajectory

2011-07-20 Thread Joe Ranalli
It depends what you're trying to do.

If you draw the straight line between the tower and the enemy and use that
vector to translate a bullet each tick, the bullets might miss the enemy.
Think about it this way, the bullet moves 2 steps toward the enemy, then the
enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
the bullet will have to change its direction through the flight.  So you
could calculate the direction vector between the bullet and the enemy every
tick and have the bullet move that direction.  That would make the bullets
kind of arc to the target.

If you want to have the bullet go straight to the right spot, you need to:
1) calculate how long the bullet will take to get to the enemy
2) calculate where the enemy will be at that time (newposition)
3) calculate how long it will take the bullet to get to newposition
4) recalculate newposition based on the new time

Technically you could iterate that repeatedly until newposition converges.
Practically, iterating once probably gets you close enough unless the
movement is extremely complicated.

On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a 2d
 game. In fact, i think of writing a tower defense game and i wonder how to
 handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)



Re: [pygame] trajectory

2011-07-20 Thread Nathan BIAGINI
Ok. But all the calcul of how long the bullet will take to reach the target
etc... will be made byn using vector? I mean, using a vector still viable?

2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use that
 vector to translate a bullet each tick, the bullets might miss the enemy.
 Think about it this way, the bullet moves 2 steps toward the enemy, then the
 enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
 the bullet will have to change its direction through the flight.  So you
 could calculate the direction vector between the bullet and the enemy every
 tick and have the bullet move that direction.  That would make the bullets
 kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition converges.
 Practically, iterating once probably gets you close enough unless the
 movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)





Re: [pygame] trajectory

2011-07-20 Thread Joe Ranalli
Yes a vector is probably appropriate.

On Wed, Jul 20, 2011 at 10:20 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok. But all the calcul of how long the bullet will take to reach the target
 etc... will be made byn using vector? I mean, using a vector still viable?


 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use that
 vector to translate a bullet each tick, the bullets might miss the enemy.
 Think about it this way, the bullet moves 2 steps toward the enemy, then the
 enemy moves 1 step, then the bullet moves 2, etc.  Because the enemy moves
 the bullet will have to change its direction through the flight.  So you
 could calculate the direction vector between the bullet and the enemy every
 tick and have the bullet move that direction.  That would make the bullets
 kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between this
 two entitites to make a sprite translation of this vector but there is maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)






Re: [pygame] trajectory

2011-07-20 Thread Nathan BIAGINI
There is a pygame object to create a 2d vector?

2011/7/20 Joe Ranalli jrana...@gmail.com

 Yes a vector is probably appropriate.


 On Wed, Jul 20, 2011 at 10:20 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 Ok. But all the calcul of how long the bullet will take to reach the
 target etc... will be made byn using vector? I mean, using a vector still
 viable?


 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in a
 2d game. In fact, i think of writing a tower defense game and i wonder how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)







Re: [pygame] trajectory

2011-07-20 Thread Joe Ranalli
No, but what you're talking about doing isn't hard.  If you're having
trouble with it, you'll need to look into some elementary physics and
trigonometry.



On Wed, Jul 20, 2011 at 10:33 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 There is a pygame object to create a 2d vector?


 2011/7/20 Joe Ranalli jrana...@gmail.com

 Yes a vector is probably appropriate.


 On Wed, Jul 20, 2011 at 10:20 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Ok. But all the calcul of how long the bullet will take to reach the
 target etc... will be made byn using vector? I mean, using a vector still
 viable?


 2011/7/20 Joe Ranalli jrana...@gmail.com

 It depends what you're trying to do.

 If you draw the straight line between the tower and the enemy and use
 that vector to translate a bullet each tick, the bullets might miss the
 enemy.  Think about it this way, the bullet moves 2 steps toward the enemy,
 then the enemy moves 1 step, then the bullet moves 2, etc.  Because the
 enemy moves the bullet will have to change its direction through the
 flight.  So you could calculate the direction vector between the bullet and
 the enemy every tick and have the bullet move that direction.  That would
 make the bullets kind of arc to the target.

 If you want to have the bullet go straight to the right spot, you need
 to:
 1) calculate how long the bullet will take to get to the enemy
 2) calculate where the enemy will be at that time (newposition)
 3) calculate how long it will take the bullet to get to newposition
 4) recalculate newposition based on the new time

 Technically you could iterate that repeatedly until newposition
 converges.  Practically, iterating once probably gets you close enough
 unless the movement is extremely complicated.


 On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI 
 nathan.o...@gmail.comwrote:

 Hi everyone,

 i would like to know what are the common way to handle trajectory in
 a 2d game. In fact, i think of writing a tower defense game and i wonder 
 how
 to handle the trajectory of the missile launch by the towers. I though of
 getting the pos of the tower and the target and create a vector between 
 this
 two entitites to make a sprite translation of this vector but there is 
 maybe
 some tricky stuff to do it.

 Thanks in advance and happy game making all :-)








Re: [pygame] trajectory

2011-07-20 Thread James Paige
Not built into pygame, but there is a good one on the pygame wiki:

http://pygame.org/wiki/2DVectorClass

On Wed, Jul 20, 2011 at 04:33:16PM +0200, Nathan BIAGINI wrote:
There is a pygame object to create a 2d vector?
 
2011/7/20 Joe Ranalli jrana...@gmail.com
 
  Yes a vector is probably appropriate.
 
  On Wed, Jul 20, 2011 at 10:20 AM, Nathan BIAGINI nathan.o...@gmail.com
  wrote:
 
Ok. But all the calcul of how long the bullet will take to reach the
target etc... will be made byn using vector? I mean, using a vector
still viable?
 
2011/7/20 Joe Ranalli jrana...@gmail.com
 
  It depends what you're trying to do. 
 
  If you draw the straight line between the tower and the enemy and
  use that vector to translate a bullet each tick, the bullets might
  miss the enemy.  Think about it this way, the bullet moves 2 steps
  toward the enemy, then the enemy moves 1 step, then the bullet moves
  2, etc.  Because the enemy moves the bullet will have to change its
  direction through the flight.  So you could calculate the direction
  vector between the bullet and the enemy every tick and have the
  bullet move that direction.  That would make the bullets kind of arc
  to the target.
 
  If you want to have the bullet go straight to the right spot, you
  need to:
  1) calculate how long the bullet will take to get to the enemy
  2) calculate where the enemy will be at that time (newposition)
  3) calculate how long it will take the bullet to get to newposition
  4) recalculate newposition based on the new time
 
  Technically you could iterate that repeatedly until newposition
  converges.  Practically, iterating once probably gets you close
  enough unless the movement is extremely complicated.
 
  On Wed, Jul 20, 2011 at 9:14 AM, Nathan BIAGINI
  nathan.o...@gmail.com wrote:
 
Hi everyone,
 
i would like to know what are the common way to handle
trajectory in a 2d game. In fact, i think of writing a tower
defense game and i wonder how to handle the trajectory of the
missile launch by the towers. I though of getting the pos of the
tower and the target and create a vector between this two
entitites to make a sprite translation of this vector but there is
maybe some tricky stuff to do it.
 
Thanks in advance and happy game making all :-)


Re: [pygame] trajectory

2011-07-20 Thread Jake b
You can define bullet speed in pixels per second.

You can use euclid (it works), but I instead suggest numpy. Which has a
vector( numpy.array ), and is useful for other game related things.


Here's a stand-alone example, uses numpy for vector movement.

https://code.google.com/p/ninmonkey/source/browse/boilerplate/pygame/4.%20with%20numpy%20for%20array/boilerplate%20-%20pygame_with_numpy-2011_jake.py

On Wed, Jul 20, 2011 at 9:33 AM, Nathan BIAGINI nathan.o...@gmail.comwrote:

 There is a pygame object to create a 2d vector?



-- 
Jake