Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:40:40+00:00 2026-06-11T03:40:40+00:00

I’ve got a simple BreakOut game (vertical, paddle along bottom) up and running but

  • 0

I’ve got a simple BreakOut game (vertical, paddle along bottom) up and running but the collision detection is a bit off.
I’m using a Rectangle.Intersect to initially check if the ball intersects the given brick at all and then if it does have 4 more Intersect calls to check whether the ball is colliding vertically (side of brick, left+right) or horizontally (top+bottom of brick).
On some occasions when the ball collides with a brick at an acute angle near the intersection of 2 horizontally adjacent bricks it removes both of them and continues in an upward direction. I assume this is a double up of collisions. I’ve forcibly exited the foreach loop which checks for rectangle intersects the moment it finds one but this hasn’t resolved issue.

This is in the main Update() function of the game class:

        foreach (Brick brick in bricks)
        {
            if (brick.CheckCollision(ball))
            {
                break;
            }
        }

This is the Brick.CheckCollision() function:

    public bool CheckCollision(Ball ball)
    {
        if (alive && ball.Bounds.Intersects(location))
        {
            alive=false;
            ball.Deflection(this);
            return true;
        }
        return false;
    }

And this is the Ball.Deflection() function. In this I’m using rectangles with no width/heigth to mark the sides of the brick. Not sure if that is the correct way:

    public void Deflection(Brick brick)
    {
        //For vertical collision (top or bottom of brick) invert Y motion
        if (this.Bounds.Intersects(new Rectangle(brick.Location.Left, brick.Location.Top, brick.Location.Right - brick.Location.Left, 0)) ||
            this.Bounds.Intersects(new Rectangle(brick.Location.Left, brick.Location.Bottom, brick.Location.Right - brick.Location.Left, 0)))
        {
            motion.Y *= -1;
            return;
        }
        //For horizontal collision (left or right side of brick) invert X motion
        if (this.Bounds.Intersects(new Rectangle(brick.Location.Left, brick.Location.Top, 0, brick.Location.Bottom - brick.Location.Top)) ||
            this.Bounds.Intersects(new Rectangle(brick.Location.Right, brick.Location.Top, 0, brick.Location.Bottom - brick.Location.Top)))
        {
            motion.X *= -1;
            return;
        }
    }

I assume I’m making a blatantly obvious logic error but if the general approach can be improved I’m all ears!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:40:42+00:00Added an answer on June 11, 2026 at 3:40 am

    Through discussion in the comments with itsme86 I’ve resolved my issues.
    I added logging (recommended by bmm6o) and confirmed that it was a doubling up of collisions caused by the ball travelling too far inside a block on one frame and still being partially inside adjacent block on next frame. I’ve decided to keep the logic simple and just move the ball back to the edge of the block it intersects when I reverse it’s direction. This is done with no Draw() function in between so as not to produce stuttering effect. I am struggling to observe any jumps or stuttering at all so if there is any it’s not visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.