1

I'm making a HTML5 Game with:

requestAnimationFrame || setInterval(updateGame(), 1E3 / 60)

Player(x,y, radius = 20) is a cirle. Bullet(x,y,bulletSpeed = 50).

Every Frame Bullet position increased 50px.

I have code calculator collision:

if(distance(Player,Bullet) <= Player.radius) Player.hp--, Bullet.remove();

But, because Bullet + 50px per frame, so Bullet across Player and keep moving (view image below).

enter image description here

How I can fix that?

Sorry about my English and Thanks for reading!

Abhishek Pandey
  • 13,302
  • 8
  • 38
  • 68
Omega P
  • 197
  • 1
  • 20
  • 2
    draw a line from your bullet's starting point to its destination, [check if your target lies on this line](http://stackoverflow.com/questions/11907947/how-to-check-if-a-point-lies-on-a-line-between-2-other-points), then check if the distance is `>=` to the crossing distance. (easier said than done I know... don't have time to write it.) – Kaiido Mar 08 '17 at 05:11
  • would the player be moving as well? you might need to take into account the player's velocity as well then :/ – derp Mar 08 '17 at 05:29
  • @Kaiido Thanks, but I just draw bullet like a circle (dot). You don't need write code for me, just some solution for that. – Omega P Mar 08 '17 at 06:58
  • @derp Player can moving, but I calculating for collision, so Player just standing and Bullet moving – Omega P Mar 08 '17 at 06:59

0 Answers0