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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:18+00:00 2026-05-28T22:53:18+00:00

Im making a collision checking system with jQuery however it doesn’t seem to work.

  • 0

Im making a collision checking system with jQuery however it doesn’t seem to work. There are two buttons. You can move one button with the right key. Once the buttons collide one of the buttons should change font colour. Right now, the button will always change colour even if its not touching the other button. Try it out, if you have some problems understanding me.

Thanks,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>my website</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                $(document).keydown(function(event) {
                    if ( event.which == 39){
                        $('.button0 input').animate({'left': '+='+Math.cos(0*Math.PI/180) *30+'px','top': '+='+Math.sin(0*Math.PI/180) *30+'px'},30);
                    };
                    button0button1();
                });
                function button0button1(){
                    var div1=$('.button0  input');
                    var div2=$('.button1 input');
                    if ((div1.offset().top+div1.outerHeight(true)) < div2.offset().top || div1.offset().top > (div2.offset().top+div2.outerHeight(true)) || (div1.offset().left+div1.outerWidth(true)) < div2.offset().left || div1.offset().left > (div2.offset().left+div2.outerWidth(true))){
                        $('.button0 input').css('color', 'rgb(0, 128, 255)');
                    };
                };
            });
        </script>
        <style type="text/css">
            .button0 input{
                position:fixed;
                left:30px;
                top:213px;
                font-family:MS Shell Dlg 2;
                font-size:8px;
                font-weight:NORMAL;
            }
            .button1 input{
                position:fixed;
                left:185px;
                top:217px;
                font-family:MS Shell Dlg 2;
                font-size:8px;
                font-weight:NORMAL;
            }
        </style>
    <body>
        <div class="button0"><input type="button" style="width: 73px;height: 67px;" value="Button"/></div>
        <div class="button1"><input type="button" style="width: 61px;height: 56px;" value="Button"/></div>
    </body>
</html>
  • 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-28T22:53:19+00:00Added an answer on May 28, 2026 at 10:53 pm

    I haven’t checked all the code (it’s a bit convoluted in its current form), but I identified two problems:

    1) You got at least one of the comparison operators wrong: (div1.offset().left+div1.outerWidth(true)) < div2.offset().left, should be >;

    2) Since the animate doesn’t immediatly change the position of your components, you should call button0button1 as a callback to animate, otherwise the buttons will collide during/at the end of the animation, but the code will report them as not colliding.

    $('.button0 input').animate({...},30,button0button1);
    // button0button1(); // Delete/comment this line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making UML sequence diagram in VS 2010RC I've observed that there is no activation
For a 2D game I'm making (for Android) I'm using a component-based system where
If I have a sprite, how would I check collision between two points? For
Im currently working on making a flash platformer engine...but my collision detect needs some
I'm making a vertical shooter game and I am having trouble with collision detection.
I'm having hard time learning collision detection by experience. I'm making a box game,
I am making a small game, with a friend. Now, I have a camera-system,
Making a simple map app, plan on adding buttons to mark specific locations But
So I'm constantly checking collision detections and whenever an enemy gets killed I remove
Making echo of a question around the web: Is the syntax for svn:ignore patterns

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.