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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:15:09+00:00 2026-05-28T20:15:09+00:00

I am making a 2d Platformer in Java, and for some reason, when the

  • 0

I am making a 2d Platformer in Java, and for some reason, when the player jumps towards a platform, it gets stuck sometimes. Here is an image of the problem:

enter image description here

As you see, I was making a jump to the top of the platform, but it got stuck.

Here is my collison code for falling/jumping:

if (guy.getJumpState() == false) {
    if (canExecuteMovement(0, 8)) {

        ...

        onGround = false;
        if (guy.getY() > this.getParent().getHeight() / 2 - 100) {
            // if you are in the middle, move the platforms.
            for (int i = 0; i < platformCount; i++) {
                if (platform[i].getVisibility() == true) {
                    platform[i].setY(platform[i].getY() - 8);
                }
            }
        } else {
            // or just move the guy if not.
            guy.moveY(8);
        }
    } else {
        onGround = true;
    }
} else {
    if (canExecuteMovement(0, -12)) {

        if (guy.getY() < this.getParent().getHeight() / 2 - 100) {
            // if you are in the middle, move the platforms.
            for (int i = 0; i < platformCount; i++) {
                if (platform[i].getVisibility() == true) {
                    platform[i].setY(platform[i].getY() + 12);
                }
            }
        } else {
            // or just move the guy if not.
            guy.moveY(-12);
        }
        jumpCount++;
        if (jumpCount >= 20) {
            jumpCount = 0;
            guy.setJumpState(false);
        }
    } else {
        jumpCount = 0;
        guy.setJumpState(false);
    }
}

Code for moving left and right:

if (guy.getDirection() == "left") {
            if (canExecuteMovement(-4, 0)) {
                if (guy.getX() < this.getParent().getWidth() / 2) {
                    // if you are in the middle, move the platforms.
                    for (int i = 0; i < platformCount; i++) {
                        if (platform[i].getVisibility() == true) {
                            platform[i].setX(platform[i].getX() + 4);
                        }
                    }
                } else {
                    // or just move the guy if not.
                    guy.moveX(-4);
                }
            }
        } else if (guy.getDirection() == "right") {
            if (canExecuteMovement(4, 0)) {
                if (guy.getX() > this.getParent().getWidth() / 2) {
                    // if you are in the middle, move the platforms.
                    for (int i = 0; i < platformCount; i++) {
                        if (platform[i].getVisibility() == true) {
                            platform[i].setX(platform[i].getX() - 4);
                        }
                    }
                } else {
                    // or just move the guy if not.
                    guy.moveX(4);
                }
            }
        }

And here is canExecuteMovement function:

private boolean canExecuteMovement(int xChange, int yChange) {
    int projectedX = guy.getX() + xChange;
    int projectedY = guy.getY() + yChange;
    Rectangle projectedBounds = new Rectangle(projectedX, projectedY, guy.getWidth(), guy.getHeight());
    for (int i = 0; i < platformCount; i++) {
        if (projectedBounds.intersects(platform[i].getBounds()) && platform[i].getVisibility() == true) {
            return false;
        }
    }
    return true;
}

I really dont know how to tackle this problem, hopefully I can get some enlightenment.

  • 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-28T20:15:10+00:00Added an answer on May 28, 2026 at 8:15 pm

    You need to track your allow/deny movement code for x and y separately. What’s happening is that if the user can’t move any further right the code stops him altogether. However, he should STILL be able to move up or down.

    Consider splitting up the conditionals in your code so that when it is assigning the new movement vectors, it sets x and y separately, checking for the ability to move in x and y individually.

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

Sidebar

Related Questions

I am making a 2d platformer in Swing java, and I am wondering how
I am making a 2D game in Android with Cocos2D, written in Java. Here
I am making a free cross platform mock up designer in Java. I have
Im currently working on making a flash platformer engine...but my collision detect needs some
I am making a 2d platformer, and am trying to get some auto-terrain generation.
I have a Java Applet that uses AWT. In some (rare) circumstances, the platform
I am making a 2D platform in Java, and I'm using a Swing timer,
He's the deal: I'm making some theorical research on .NET and Java platforms for
I'm currently making an IDE for the Java platform. This IDE for education purposes
I am making a basic platform game for the iPhone and I have encountered

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.