I am having a tough time attempting to resolve the reflexion angles when the ball collides with one of many brick’s corners (sq. vertices) in my brick breaker recreation.
The collision detection system is working positive, and I’ve already managed to resolve the collisions when the ball hits the brick from its sides. The reflection angles are working positive when the ball hits both the partitions or the brick’s sides, and I’ve even managed so as to add slight angle increments to those angles to stop the ball to bounce indefinitely from one facet to the opposite.
However in the case of the brick’s corners, issues get messy. The collision decision works positive to distinguish the edges from the corners. Generally, I am selecting two coordinates x,y (new and former) to find out the ball positions and utilizing Math.atan2(newY-prevY, newX-prevX) perform to get the angles to calculate cos and sin for spdX and spdY for the collision decision on the partitions and the brick’s sides. For the corners half, I am selecting the newX,newY ball coordinate (heart level) when it collides with one of many bricks corners and selecting the x,y coordinate from this nook to find out the conventional line, by utilizing Math.atan2(newY-cornerY, newX-cornerX). Notice that I’ve made the changes for every nook x,y to get the proper values (including width to x for the proper corners and peak to y for the underside corners). Then, I calculate the angle of incidence incAngle = Math.abs(Math.atan2(prevY-newY, prevX-newX) – regular) and the reflection angle refAngle = regular – incAngle. Lastly I calculate spdX = Math.cos(refAngle) and spdY = Math.sin(refAngle). It appears the mess occurs once I calculate incAngle and refAngle. I’ve already inverted indicators on each, used Math.abs(), and in all circumstances a few of the reflection angles present positive, a few of them even completely, however in sure positions, relying of the inciding angle, the reflection angle exhibits incorrectly. Definetly the angles signal concern nonetheless confuses me so much.
The place am I doing incorrect? Is there one thing lacking? I am growing my recreation from scratch utilizing Java and Eclipse and am attempting to make the code so simple as I can, since I do not perceive a lot of these fairly difficult advanced Math equations (I had made some analysis about them, however didn’t perceive a factor), and do not use exterior physics/collision engines in it.
Greatest regards.