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 7614531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:25:37+00:00 2026-05-31T02:25:37+00:00

I have been implementing various forms of simple collision detection with varying results. I

  • 0

I have been implementing various forms of simple collision detection with varying results. I have a fairly good working version of collision detection, but there are some odd behaviors that I can’t work out.

Just for a reference, i’m making a simple pong game, and trying to refine the collision. The problems I get are when the ball collides with the paddle on either the top or bottom side. In those cases, the ball hovers above (or below) the paddle and does not move. I’m guessing this is because of how i’m checking for collision and how i’m altering the movespeed of the ball.

I would like to implement a way I differentiate between top/bottom and left/right collision but this is the only method that works decently:

static void CheckCollision(PActor object1, PActor object2, PInput pinput)
{
    if ( CheckObjectCollision( object1, object2 ) )
    {
        AdjustMoveSpeed( object1, object2, pinput );
    }
}



static bool CheckObjectCollision(PActor object1, PActor object2)
{
    int object1LeftBound = object1.position.x;
    int object1RightBound = object1.position.x + object1.actorTextureXSize;
    int object1TopBound = object1.position.y;
    int object1BottomBound = object1.position.y + object1.actorTextureYSize;

    int object2LeftBound = object2.position.x;
    int object2RightBound = object2.position.x + object1.actorTextureXSize;
    int object2TopBound = object2.position.y;
    int object2BottomBound = object2.position.y + object2.actorTextureYSize;

    if ( object1RightBound < object2LeftBound )
        return false;

    if ( object1LeftBound > object2RightBound )
        return false;

    if ( object1BottomBound < object2TopBound )
        return false;

    if ( object1TopBound > object2BottomBound )
        return false;

    return true;        
}

I am guessing that the root of some of the problems i’m having is the function AdjustMoveSpeed, here it is:

static void AdjustMoveSpeed(PActor object1, PActor object2, PInput pinput)
{
    PVector prevMouseLocation = pinput.GetPrevMouseLocation();
    PVector currMouseLocation = pinput.GetCurrMouseLocation();

    int currentMoveSpeed;
    int nextMoveSpeed;

    if (typeid(object1) == typeid(PBall))
    {

        object1.moveSpeed.x *= -1;  

        if ( typeid(object2) == typeid(PPlayer) )
        {
            currentMoveSpeed = object1.moveSpeed.y;
            nextMoveSpeed = prevMouseLocation.y  - currMouseLocation.y;

            object1.moveSpeed.y = (prevMouseLocation.y  - currMouseLocation.y) * -1; 

        }
        else
        {
            if (object1.moveSpeed.y > 0)
                object1.moveSpeed.y *= -1;
        }
    }
    else if (typeid(object2) == typeid(PBall))
    {

        object2.moveSpeed.x *= -1;

        if ( typeid(object1) == typeid(PPlayer) )
        {
            currentMoveSpeed = object1.moveSpeed.y;
            nextMoveSpeed = prevMouseLocation.y  - currMouseLocation.y;

            object2.moveSpeed.y = (prevMouseLocation.y  - currMouseLocation.y) * -1; 
        }
        else
        {
            if (object2.moveSpeed.y > 0)
                object2.moveSpeed.y *= -1;
        }
    }       
}

What I was attempting to do with AdjustMoveSpeed, is first check to see which object is the ball, after this, multiply the x move speed by -1 to reverse its direction. After this, I check to see if the other object is a player, if so I set the y move speed to the difference between the previous mouse location and current mouse location. This is here to give the player option to change the balls y speed, or add spin.

I’ve tried checking for intersection between objects so that I can get a specific side, and the result is the ball just flying in the middle of the screen without actually hitting either paddle.

How do I properly check for collision detection on two objects that are squares?

How can I fix AdjustMoveSpeed so that it works properly with collision detection?

Lastly, how do I keep the momentum of the ball of its current speed is greater than the difference of the mouse location before and after the hit?

I’ve tried taking comparing the absolute value of currentMoveSpeed and nextMoveSpeed but then the ball doesn’t change y speed. Something like this:

if ( abs(currentMoveSpeed) < abs(nextMoveSpeed )
    object1.moveSpeed.y = (prevMouseLocation.y  - currMouseLocation.y) * -1;
else
  object1.moveSpeed.y *= -1
  • 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-05-31T02:25:38+00:00Added an answer on May 31, 2026 at 2:25 am

    Pong is simple enough that, rather than moving the ball each frame and checking for a collision with a paddle, you can actually solve the equation for when the paddle and ball will collide – if that time is less than one frame, there is a collision.

    This completely eliminates the issue of the ball moving so fast it moves through the paddle, an issue that plagues many pong-clones that use the naive method of collision-detection.

    This solution is called continuous collision detection – see this answer for more information.

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

Sidebar

Related Questions

I have been implementing RSA security for a project I am working on. I'm
So I have been working on properly implementing a quicksort algorithm for a homework
Have been searching how to convert a dictionary to a string. But the results
I have been working on implementing the Ancestry gem in my rails app, I
I have been working on implementing a (1) server, (n) worker role servers setup
I have been working on implementing the first 6 functions of the NSComparisonMethods protocol
I am working on a data warehousing project, and therefore, I have been implementing
I am implementing a system where I need real-time updates. I have been looking
As a lot of people have been doing so far, I'm implementing the FragmentTabsPager
Have been working on this question for a couple hours and have come close

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.