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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:15+00:00 2026-05-31T23:17:15+00:00

I am trying to create a jump method in XNA, but I am facing

  • 0

I am trying to create a jump method in XNA, but I am facing a lot of problems, it doesn’t work for me, I’ve been trying doing it for like 2 hours long and still no “luck”. Can anybody give me a code sample, or at least a direction?

Note: I want the jump to be realistic, using gravity and such.

Thank you!
I erased all my work but here’s the latest I tried, I know it shouldn’t work for sure, but still..

  public void Jump(GameTime gameTime)
    {
        float currentTime = (float)0.1;
        if (position.Y == 200)
        {
            position.Y += velocity.Y*currentTime -gravity * (float)(Math.Pow(currentTime,2)) / 2;
        }
        if (position.Y == 200 + jumpHeight)
        {
            position.Y -= velocity.Y * currentTime - gravity * (float)(Math.Pow(currentTime, 2)) / 2;
        }
    }
  • 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-31T23:17:16+00:00Added an answer on May 31, 2026 at 11:17 pm

    I see that you’ve learned the equations of motion from your code (which I don’t think was in place when I made my comment). However you’re a little off, your issue is with your time variable. You’re passing in your game time, but then using .1f for your time variable. What you really want for your time variable is the time since you started the jump. Further, position.Y is unlikely to ever be exactly equal to 200 or 200 + jumpHeight. It’s a float (I assume), so you can never trust that it’ll be a nice round number. If you want to specify an exact maximum jump height, you’ll have to perform some equations before and set your velocity.Y accordingly (solve for when velocity equals 0 i.e. the top of your jump).

    So, to fix your original code I think something like this will work, albeit totally untested:

       public void Jump(GameTime gameTime)
       {
           if(jumping && position.Y > groundLevelAtPlayer) {
               //Get the total time since the jump started
               float currentTime = gameTime.totalTime - character.timeofjumpStart;
               //gravity should be a negative number, so add it
               position.Y += (velocity.Y * currentTime)
                   + (gravity * ((float)(Math.Pow(currentTime, 2)) / 2));
           }
           else 
           {
               jumping = false;
           }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying create a delegate representation of constructor by emitting a Dynamic Method,
tl;dr: Jump to the last paragraph Recently I've been trying to use RSpec's request
Im trying to create a game with jQuery, but none of the options after
I'm trying to create a menu that works like the android notification drop-down area.
I'm stumped with this one, I've been at it hours, trying to get jQuery
Im trying to to create a simple 4 function calculator using a jump table
I'm trying to work with Threadding and it seems to me like it's suspiciously
I have been trying to create a simple calculator. Using PHP I managed to
I'm trying create a method that returns the sum of all values in an
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

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.