2d game : fire at a moving target by predicting intersection of projectile and unit

后端 未结 11 770
庸人自扰
庸人自扰 2020-11-28 22:26

Okay, this all takes place in a nice and simple 2D world... :)

Suppose I have a static object A at position Apos, and a linearly moving object B at Bpos with bVeloci

11条回答
  •  眼角桃花
    2020-11-28 22:52

    I grabbed one of the solutions from here, but none of them take into account movement of the shooter. If your shooter is moving, you might want to take that into account (as the shooter's velocity should be added to your bullet's velocity when you fire). Really all you need to do is subtract your shooter's velocity from the target's velocity. So if you're using broofa's code above (which I would recommend), change the lines

      tvx = dst.vx;
      tvy = dst.vy;
    

    to

      tvx = dst.vx - shooter.vx;
      tvy = dst.vy - shooter.vy;
    

    and you should be all set.

提交回复
热议问题