Arkanoid ball/block collision question

Started by
1 comment, last by Pemaden 15 years, 5 months ago
Hey, I'm making an Arkanoid clone. I'm using BoundingSphere/BoundingRectangle collision detection and it is working but I am just inverting the Y direction of the ball when it hits a Block. I want to be able to find which side of the Block the Ball hits so I can then determine the new direction of the ball (not just invert Y if there is a collision). Any help would be great :)
Advertisement
incoming angle = atan2(vely, velx).

If you didn't want to use that you could switch to polar coordinates like so...

example: let ball have velocity of 6
float velocity = 6;

starting angle of pi
float angle = 3.14;

now, if you want to change the direction of the angle, just change "angle" to any angle you want, and if you want to change the velocity, set "velocity" to the new value.

determining new coordinates is very simple

new_x = old_x + velocity * cos(angle);
new_y = old_y + velocity * sin(angle);


Hope that helps, cheers!
What I did when I was working on an Arkanoid clone was first check for a collision similar to how you are doing it. After I knew the ball was colliding with the brick, I did some calculations to find out where exactly it was colliding. The closer it was to the center, the steeper I made the y velocity (up to the negative-y change you are doing now).

Since you know the x and y positions of both the block and the ball it should be pretty straight-forward to find the position. Say take how far from the left edge of the brick the ball is.

I doubt this is the closest you can get to replicating actual arkanoid, but it worked for me.

This topic is closed to new replies.

Advertisement