Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 11:44:20 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Quadratics or otherwise for jumping physics?
Pages: [1] 2
Print
Author Topic: Quadratics or otherwise for jumping physics?  (Read 1986 times)
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« on: October 12, 2012, 06:33:47 AM »

I am implementing jumping in my first game, and I am wondering whether it is better to use a system where my character moves up to a certain level, then cuts out jump and turns on gravity, or to use a system with quadratics. I am currently using the former, but my friend who is slightly better says I should use quadratics. He is better at programming, but doesn't do games. I was wondering what you gentlemen would use?   Gentleman
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
enthrallstudios
Level 0
***


View Profile
« Reply #1 on: October 12, 2012, 06:37:02 AM »

It really depends on how you want the movement to feel. If you are making a 2D platformer, and want really tight controls(think Megaman or Super Meatboy), you want to have absolute control over what the movement is. You want a jump to always be a constant distance, and you generally want to be able to change your direction in mid-air, even though it's not physically accurate at all.

All that being said, what "feel" are you going for?
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #2 on: October 12, 2012, 06:46:00 AM »

I want the player to hit the space bar once, jump up to a specific height, then have the gravity take over. Like Mario or Braid. Not like Cave Story or the two you mentioned.
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
enthrallstudios
Level 0
***


View Profile
« Reply #3 on: October 12, 2012, 06:59:07 AM »

Mario's controls are quite similar to the two I mentioned. You can change direction in mid-air. Regardless, you want a simple approach when it comes to 2D games in most cases. If you are  looking to copy the feel of Mario, simplicity will be your definite solution. I will say now that while it's not impossible, I would recommend staying away from physics engines like Box2D as it can be difficult to get the right feel.

There is an interesting video about this here :



Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #4 on: October 12, 2012, 07:02:03 AM »

Alright thanks. I'll work out the bugs in my solution.
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #5 on: October 12, 2012, 07:07:09 AM »

There was another thread on this a little bit ago:

Jumping physics help

But I'll reiterate myself:

Mario works as follows (roughly) -- (I'm assuming Left = -x, Right = +x, Up = +y, Down = -y)

1) The player hits jump, some value is added to the y velocity
2) If the player continues to hold the jump button and the player is moving up then a factor is multiplied (between 0 and 1) to the gravity applied to the player
3) If the player lets go of the jump button or the player starts falling down then normal gravity is applied

This allows for variable height jumping in a way that is completely unphysical, but feels natural.
Logged
Cheezmeister
Level 3
***



View Profile
« Reply #6 on: October 12, 2012, 07:55:17 PM »

What exactly does your buddy mean by "use quadratics"?

Are we talking straight-up
Code:
height = At^2 + Bt + C
, or some fancier technique I'm not familiar with?
Logged

෴Me෴ @chzmstr | www.luchenlabs.com ቒMadeቓ RA | Nextris | Chromathud   ᙍMakingᙌCheezus II (Devlog)
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #7 on: October 13, 2012, 12:49:18 AM »

@Fallsburg: Yeah, I glanced over that before I started. However, my game only makes the character go up to a certain height, then it cuts out the height and implements gravity. Does your one mean that gravity goes on all the time, but that it just gets stronger?

@Cheezmeister: Yeah, I guess so.
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Gregg Williams
Level 10
*****


Retromite code daemon


View Profile WWW
« Reply #8 on: October 13, 2012, 07:41:05 PM »

Typically you want gravity to always be on. This allows for elegant handling of things like stepping off a ledge, stairs, etc.
Logged

Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #9 on: October 13, 2012, 08:00:15 PM »

Alright thanks. My previous version allowed the character to fall off a ledge, and jump in midair, and return to the same ledge.  Durr...?
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #10 on: October 14, 2012, 01:23:13 PM »

Yeah, you also typically want to test if the player is on the ground to see if a jump should be allowed (barring air jumps where you typically want to check the number of times a player has jumped).

Logged
Quarry
Level 10
*****


View Profile
« Reply #11 on: October 16, 2012, 01:35:32 AM »

What I often have is a yVel float that is set to a negative number when you press the jump key and when you are on air it's always increased by the amount of gravity so that I get a nice parabolic movement
Logged
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #12 on: October 16, 2012, 05:07:32 AM »

That's fine, if you are ok with a constant jump height. 
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #13 on: October 16, 2012, 05:15:41 AM »

I have another problem guys. Every update, my gravity should get stronger by .01 (I can choose the exact number later), but Java (my chosen language) does not allow floats this precise. I have to change it to a double to be that precise. However, most of the methods I took from my game engine use floats. That means I can't just convert all floats to doubles. Should I convert my double to a float every update method, or does anyone have an idea? I hope I understood what you guys said above. If I'm wrong in anything please do tell. 
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Quarry
Level 10
*****


View Profile
« Reply #14 on: October 16, 2012, 05:18:06 AM »

ctrl + h float double
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #15 on: October 16, 2012, 05:19:51 AM »

I'm not quite sure what that means....  Shrug
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Quarry
Level 10
*****


View Profile
« Reply #16 on: October 16, 2012, 05:21:38 AM »

Replace all floats in your project to doubles then you'll have no probs
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #17 on: October 16, 2012, 05:24:50 AM »

I have a couple methods in Slick2d that only accept floats, so that won't work too well, unless I edit the source code.
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Quarry
Level 10
*****


View Profile
« Reply #18 on: October 16, 2012, 05:26:42 AM »

What methods do you use even? You can typecast most of the doubles to float
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW
« Reply #19 on: October 16, 2012, 05:28:33 AM »

ARGH. Found out my own problem. I just found out that you can make floats decimal points by adding f at the end. Didn't know about that 'til now. Thanks anyways. Quarry, thanks for trying. (*Bows shamefully and walks out slowly.)
Logged

Do I need a signature? Wait, now that I have a Twitter I do: https://twitter.com/theimpmaster
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic