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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:46:45+00:00 2026-05-26T01:46:45+00:00

Basically I have a bunch of rectangles floating around at 8 different angles (45

  • 0

Basically I have a bunch of rectangles floating around at 8 different angles (45 degrees, 90 degrees etc). I have collision detection going on between all of them, but one thing still doesn’t work as it should. I don’t know if I’m just not thinking or what, but I can’t seem to get the resulting angles right. I’ve also tried searching multiple places, but haven’t really gained anything from what I’ve found.

NOTE: the angle system here starts at 0 at the top and increases clockwise.
NOTE: all rectangles have the same mass

Say one rectangle going straight right (90 degrees) hits another going straight left (270 degrees). They will hit off of each other just fine.

Now say one going left gets hit by one going up. Here I can’t simply reverse the angles or anything.

If you have more than one way, consider the following: unless I rearrange the CD so it spreads into the other code, I have the positions of all of the rectangles. The CD checks by seeing if two are overlapping, not by comparing where they are going.

As I’ve been working on pretty much everything except for the collision detection until now, I only have tonight left to get it working and add a few other small things before I’m done.

If you know of a way to make the angles come out right without hardcoding, great. At this point I’m ready to hardcode it (not too much really) if all I have is which rectangle hits the other (ex 2), or if they both do (ex 1). Either one is really helpful.

  • 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-26T01:46:46+00:00Added an answer on May 26, 2026 at 1:46 am

    I think you mean something like this…

    Each Rectangle has this functionality, testing against, say an array of other objects.

    Obstacle* obstacle = new Obstacle;
    Obstacle** obstacles = obstacle*[];
    
    For(int i = 0; i <3; i++)
    {
    obstacles[0] = New Obstacle(x,y, etc...);
    etc...
    }
    

    Or something similar… this is a little rusty

     void collision(obstacles)
        {
            for(int i = 0; i < obstacles.sizeOf();i++)
               {
                //bottom y
                if((this.ypos + this.height) > (obstacles[i].ypos - obstacles[i].height))
                    obstacles[i].doYCollision(this);
    
    
                //top y
                if((this.ypos - this.height) < (obstacles[i].ypos + obstacles[i].height))
                    obstacles[i].doYCollision(this);
    
    
                //right x
                if((this.xpos + this.width) > (obstacles[i].xpos - obstacles[i].width))
                    obstacles[i].doXCollision(this);
    
                //left x
                if((this.xpos - this.width) < (obstacles[i].xpos + obstacles[i].width))
                    obstacles[i].doXCollision(this);
               }
        }
    

    again im a little rusty but if you follow it you should be able to relaise what im doing.

    then all you need is the resulting function calls.

    void doYCollision(Obstacle obstacle)
    {
      // Whatever y direction they are going do the opposite
      obstacle.yDir = obstacle.yDir * -1;
    }
    void doXCollision(Obstacle obstacle)
    {
      // Whatever x direction they are going do the opposite
      obstacle.xDir = obstacle.xDir * -1;
    }
    

    where yDir, xDir is the x and y velocity of the current object.

    i should point out again this is very rusty and without having some code from you this is the best ive got. but either way this should start you off into collision detection, the code above shoudl allow for all collisions with all obstacles/objects/pink flamingos/ whatever youve got. Im hoping also that itll do what you want when it comes to multiple collisions at the same time.

    You shouldnt need to worry too much about the exact angle (unless you need it for something else), as velocity is a vector mass so has both speed and direction and you can get direction by treating x and y as two different elements. You can do this using the dot product method aswell => http://www.topcoder.com/tc?d1=tutorials&d2=geometry1&module=Static, but if they are just rectangles this should be fine.

    Hopes this helps

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

Sidebar

Related Questions

Basically I have a bunch of unmanaged VC++ static libraries. And the VC++ GUI
I'm getting confused by pointers in objective-c. Basically I have a bunch of static
So basically, I have a bunch of TextBoxes that the user gets to fill
We have a set of applications that basically display a bunch of bitmaps and
I have a page that will basically be used to concatenate a bunch of
I have a simple sketch (in Processing ), basically a bunch of dots wander
Basically I have a getjson call to call for a bunch load of data.
I have a bunch of methods that make use of jquery to basically generate
Basically, I have a bunch of files with a common prefix ( logo%d.jpg )
Basically I have a bunch of submission forms that gather data in a generic

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.