+ 2

How can we make collosion between two objects by using js?

Please anybody explain

2nd Mar 2021, 12:14 PM
Little Coder
Little Coder - avatar
4 Answers
+ 4
There is a MDN tutorial dedicated for that. https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript/Collision_detection Basically, this is the logic (from MDN) 👇 If the center of the ball is inside the coordinates of one of our bricks, we'll change the direction of the ball. For the center of the ball to be inside the brick, all four of the following statements need to be true: The x position of the ball is greater than the x position of the brick. The x position of the ball is less than the x position of the brick plus its width. The y position of the ball is greater than the y position of the brick. The y position of the ball is less than the y position of the brick plus its height.
2nd Mar 2021, 12:24 PM
Ore
Ore - avatar
+ 2
@Little Coder Without what?
3rd Mar 2021, 11:47 AM
Ore
Ore - avatar
+ 1
Is there is no easy way without it? @Ore
3rd Mar 2021, 11:38 AM
Little Coder
Little Coder - avatar
0
Without the code. Which you given in the link
3rd Mar 2021, 11:48 AM
Little Coder
Little Coder - avatar