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

  • Home
  • SEARCH
  • 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 3283284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:22+00:00 2026-05-17T20:01:22+00:00

Would like to know which direction player hits terrain tile from (just a simple

  • 0

Would like to know which direction player hits terrain tile from (just a simple up/down, left/right). Everything I find is either too simple, or is much more complex and seemingly way too much for what I need, like with AABB (granted it’s hard to tell, my brain has trouble digesting what amounts to really long equations). What I’ve got so far is the result of spending better part of today reading and experimenting:

public int move(double toX, double toY) {

    int col = COLLISION_NONE; //these are bit flags, in case I collide with a block to my right as well as below me

    double nextX = mX+(toX*main.getDelta()); //delta regulates speed
    double nextY = mY+(toY*main.getDelta());

    if(mTerrainCollision){

        int w = GameView.GameLoop.TILE_WIDTH;
        int h = GameView.GameLoop.TILE_HEIGHT;

        for(int i = -2; i <= 2; i++) //broad tile picking will be optimized later, better trace around players path
            for(int j = -2; j <= 2; j++) {
                GameTerrain.Block block = main.mTerrain.get(((int)Math.round(mX)/w)+i,((int)Math.round(mY)/h)+j);
                if(block.type != GameTerrain.BLOCK_TYPE_NONE) {

                    if(nextX+w >= block.x() && mX+w <= block.x()){ //COLLISION ON THE RIGHT?
                        if(mY+h > block.y() && mY < block.y()+h) { //<THIS is a problem line, see below
                            nextX = block.x() - w;
                            xMomentum = 0;

                            col |= COLLISION_RIGHT;
                        }
                    }

                    else if(nextX < block.x()+w && mX >= block.x()+w){ //COLLISION ON THE LEFT?
                        if(mY+h > block.y() && mY < block.y()+h) { //same as above, make sure were on the same plane
                            nextX = block.x() + w;
                            xMomentum = 0;

                            col |= COLLISION_LEFT;
                        }
                    }


                    if(nextY+h >= block.y() && mY+h <= block.y()){ //COLLISION ON THE BOTTOM?
                        if(mX+w > block.x() && mX < block.x()+w) { //make sure were on the same plane
                            nextY = block.y() - h;
                            yMomentum = 0;

                            col |= COLLISION_DOWN;
                        }
                    }

                    else if(nextY < block.y()+h && mY >= block.y()+h){ //COLLISION ON THE TOP?
                        if(mX+w > block.x() && mX < block.x()+w) { //make sure were on the same plane
                            nextY = block.y() + h;
                            yMomentum = 0;

                            col |= COLLISION_UP;
                        }
                    }
                }
            }
    }

    mX = nextX;
    mY = nextY; 

    return col;

}

It works… mostly. Player won’t phase through blocks even after long sleeps making the delta skyrocket. The collision detection itself works unless the player’s previous position (mX/mY) are not on the same plane as the block we’re checking (see commented line with “THIS…”). Say we’re perfectly diagonal to a block and moving straight for it, player will zip right through. I’ve been scratching my head for a while now trying to figure out how to go about solving this last issue, preferably without a major rehaul of everything, but if it had to come to that oh well! I’m only interested in simple collision data for things like “Did I touch a floor this frame? Ok I can jump”, “Am I touching a wall right now? Ok I can wall jump, but not if I also touched a floor”, etc.

  • 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-17T20:01:23+00:00Added an answer on May 17, 2026 at 8:01 pm

    Grow the wall’s AABB by the size of the object’s AABB (keeping the center of the wall’s AABB fixed), construct a line segment from the object’s before and after positions (use the center of the object’s AABB), then do a segment-AABB intersection test.

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

Sidebar

Related Questions

I would like to know which dependency described in my pom.xml brings a transitive
I would like to know which one is the best material that I can
I've got an executable file, and I would like to know which version(s) of
I would like to know where can I find the code which eclipse uses
I would like to know if I can open 2 different diagrams using MS
I would like to know what semaphores, messageQueues, etc... are active in my vxWorks
I would like to know what kind of tool you use for writing your
I would like to know what's the best technique to do single sign-on in
I would like to know what would be the best way to do unit
I would like to know if there is any way to add custom behaviour

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.