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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:12:33+00:00 2026-05-27T13:12:33+00:00

Greetings stackoverflow community! I am working on an Android game that uses Box2D for

  • 0

Greetings stackoverflow community!

I am working on an Android game that uses Box2D for collision detection and physics. Right now, I’m implementing a basic platformer system. Jumping is in place, but it has a small glitch. The following function is meant to determine if a player is on the ground. Simple, right? Well, it works okay, unless the player is right next to a wall, in which case it’ll just let him constantly jump up, as the function will still return true, even if the wall isn’t directly below the player.

I have tried adding additional x-checks to make sure that I’m colliding with something that’s directly under me, but to no avail.

private boolean isGrounded(float deltaTime) {               
    List<Contact> contactList = world.getContactList();

    for(int i = 0; i < contactList.size(); i++) {
        Contact contact = contactList.get(i);
        if(contact.isTouching() && (contact.getFixtureA() == sensorFixture ||
           contact.getFixtureB() == sensorFixture)) {               

            Vector2 pos = body.getPosition();
            WorldManifold manifold = contact.getWorldManifold();
            boolean below = true;
            Vector2 cpoint;
            for(int j = 0; j < manifold.getNumberOfContactPoints(); j++) {
                cpoint = manifold.getPoints()[j];
                below &= (
                            (cpoint.y < pos.y - 0.15f) 
                            && (cpoint.x > pos.x - w/2 + 3f)
                            && (cpoint.x < pos.x + w/2 - 3f)
                        );

                if(below) return true;
            }

            return false;
        }
    }
    return false;
}

So, does anyone have any pointers towards what I could do to make the isGrounded check more efficient?

Thanks in advance! 🙂

  • 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-27T13:12:34+00:00Added an answer on May 27, 2026 at 1:12 pm

    I’m not familiar with Box2d, but my first thought would be to check the orientation of the object you are in contact with. A quick check of the documentation will tell you that WorldManifold has a getNormal which provides a local normal that points from fixtureA to fixtureB. From there you compare the orientation to the X-axis or Y-axis using a dot product. Then you can threshold how steep a surface you want to let the player be able to jump on. You may need to convert the local normal to world space.

    Sources:

  2. Box2d Manual
  3. LibGDX Docs
  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

Greetings, I'm working on a game project that uses a 3D variant of hexagonal
Greetings, I'm working in a code base that uses alot of anonymous methods, where
Greetings StackOverflow community! For this new project I'm required to write a trigger which
Greetings to the stackoverflow community, I am currently following a bioinformatics module as part
Greetings! As part of Ruby learning, I am working on a project that involves
Greetings, I'm working on an application inspired by the ZoomingPDFViewer example that comes with
Greetings Stack Overflow community. I'm trying to make a function that can pop all
Greetings to all! This is my first question here on stackoverflow. I have a
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, stack overflow In my database, I already have one table, 'contacts' that contains

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.