Jump to content
  • Advertisement
Sign in to follow this  
johns700

Arkanoid ball/block collision question

This topic is 3687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!