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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:36:56+00:00 2026-05-28T03:36:56+00:00

I have been writing a Game Engine and I have a problem with my

  • 0

I have been writing a Game Engine and I have a problem with my actor class. I want to determine the collision with a rectangle (above) and a side of a rectangle. I had written two methods for them.

public boolean isLeftCollision(Actor actor) {
    boolean bool = false;
    Rectangle LeftBounds = new Rectangle(x, y, x-velocity, image.getHeight(null));
    bool = LeftBounds.intersects(actor.getBounds());
    return bool;
}

public boolean isRightCollision(Actor actor) {
    boolean bool = false;
    Rectangle RightBounds = new Rectangle(x+image.getWidth(null), y, image.getWidth(null)+velocity, image.getHeight(null));
    bool = RightBounds.intersects(actor.getBounds());
    return bool;
}

Here velocity is the movement for next step.

But they both give me error (ie., false judgements). How can I solve this in the actor class.

  • 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-28T03:36:57+00:00Added an answer on May 28, 2026 at 3:36 am

    I admit I can hardly read your code and I’m sorry if my answer isn’t helpful. My guess is that the velocity in the collision produces the errors. Depending on how often you check and what values velocity holds you might register collisions that haven’t occured yet…

    I’d do the collision detection in two steps.

    1. Test for a collision
    2. Determine if it’s above or to one side.

    here’s some pseudocode:

    Rectangle self_shape=this.getBounds();
    Rectangle other_shape=actor.getBounds();
    bool collision = self_shape.intersects(other_shape);
    if(collision){
        //create two new variables self_centerx and self_centery
        //and two new variables other_centerx and other_centery
        //let them point to the coordinates of the center of the
        //corresponding rectangle
    
        bool left=self_centerx - other_centerx<0
        bool up=self_centery - other_centery<0
    }
    

    That way you can look where the other actor is positioned relative to you. If it’s above or to one side.

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

Sidebar

Related Questions

I have been writing an OpenGL game engine for a while which uses SDL
I've been learning Ruby for a class and have been writing a sample game.
I have been recently writing a UDP server for a 2D shooter game I
I've been working on writing my own networking engine for my own game development
Background: I am writing a flash game and have encountered a problem. I have
I've been writing a full game engine on top of LibGDX for sometime now
I have been designing a component-based game library, with the overall intention of writing
So I am writing a class that plays the card game war. I have
I have been writing C++ Console/CMD-line applications for about a year now and would
I have been writing unit tests using NUnit and Moq with my Silverlight code

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.