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

The Archive Base Latest Questions

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

im making a platform type of game. I made my main character a rectangle

  • 0

im making a platform type of game. I made my main character a rectangle using the Rectangle class, as well as the platforms. The platforms are constantly moving upward on the screen, and when my character collides with the top of the platform, I want him to land and move at the same speed as the platform, otherwise, he should be falling. I got everything to work except the falling part. If i turn on the falling, it never stays on the platforms, but if I turn on falling, it works fine. Basically the character is suppose to be falling the whole time unless it lands on a platform, then its y direction/speed should change to that of the platforms.

here is that part of the code, any help on how to make the character fall whenever not colliding with the platforms would be great. I know what I am doing may not be the most effiecent way to do this, if there is a better way I would love to know. I’m new to xna, but I know java/c#

            Rectangle playerRec = new Rectangle((int)player.position.X, (int)player.position.Y,player.width, player.height);
        foreach (Platforms platform in platforms)
        {
            Rectangle platformRec = new Rectangle((int)platform.position.X, (int)platform.position.Y, platform.width, platform.height);
            if ((playerRec.Intersects(platformRec) && (playerRec.Y + playerRec.Height) - platformSpeed < platformRec.Y) &&
                (playerRec.X < platformRec.X + platformRec.Width && playerRec.X + playerRec.Width > platformRec.X))
            {
                gravity = 0;
                player.position.Y -= platformSpeed;

            }
            else if(player.position.Y != platform.position.Y)
            {
                gravity = 5;
                //player.position.Y += gravity;
            }
  • 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-27T20:59:02+00:00Added an answer on May 27, 2026 at 8:59 pm

    Your problem is most likely that you aren’t BREAKING OUT of the loop when you hit an intersection. You’re looping through ALL the platforms every time so when one intersects, gravity will = 0 but then guess what, it’ll check the next one and gravity will be 5 again.

    You’d have to restructure your loop or you could check out this 2D physics engine to handle most of this stuff for you:

    http://farseerphysics.codeplex.com/

    • 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 game for the Android platform. The character is supposed
I am making a basic platform game for the iPhone and I have encountered
I'm making a simple 2d game for the android platform, which works perfectly from
I'm making a simple cross platform chat program. I'm using wXWidgets for the GUI
I'm making a simple platform game in Flash CS5 and Actionscript 3.0. When the
I am making a top-down platformer game using sprites. I would like to add
I'm making a small platform game with the canvas element and I'm having trouble
I am making a 2D platform in Java, and I'm using a Swing timer,
I am attempting to integrate an existing payment platform into my webshop. After making
I have a conceptual question... I am making an Intranet application (Web platform) for

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.