How to make a proper check for collision in the game JS?

Hello, dear programmers!)

Create the game!)

I want to do so if "PLAYER" has passed the red border, "BOT"starts on the "PLAYER" to shoot

the question of whether to do the usual proverki ? or need using TRIG - (Math.atan2(), Math.cos(), Math.sin())

the shot of the Bot towards the player, did. But,the function of the shot should fire when the Player crossed the red border

5e4938ffc22c8861951432.png
April 7th 20 at 15:18
2 answers
April 7th 20 at 15:20
Solution
const distanceBetween = (a,b) => Math.sqrt( (a.x - b.x) ** 2 + (a.y - b.y) ** 2 )

if (distanceBetween(bot, player) < bot.scope) 
 bot.shootIn(player)
Thank You Very Much!) - timothy.Simon commented on April 7th 20 at 15:23
April 7th 20 at 15:22
I'm new to JS, but why not to check if the coordinate of the player,given its size, falls into the circle equation, then it is possible to shoot. The equation of the circle: x^2+y^2 = R^2.
type
if(xigroka^2+yigroka^2<=R^2){
//ono strelyaet
}

Find more questions by tags CanvasJavaScript