Impmaster
|
|
« 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?
|
|
|
Logged
|
|
|
|
enthrallstudios
|
|
« 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
|
|
« 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
|
|
|
|
enthrallstudios
|
|
« 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
|
|
« Reply #4 on: October 12, 2012, 07:02:03 AM » |
|
Alright thanks. I'll work out the bugs in my solution.
|
|
|
Logged
|
|
|
|
Fallsburg
|
|
« Reply #5 on: October 12, 2012, 07:07:09 AM » |
|
There was another thread on this a little bit ago: Jumping physics helpBut 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
|
|
« Reply #6 on: October 12, 2012, 07:55:17 PM » |
|
What exactly does your buddy mean by "use quadratics"? Are we talking straight-up , or some fancier technique I'm not familiar with?
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« 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
|
|
|
|
Gregg Williams
|
|
« 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
|
|
« 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.
|
|
|
Logged
|
|
|
|
Fallsburg
|
|
« 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
|
|
« 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
|
|
« Reply #12 on: October 16, 2012, 05:07:32 AM » |
|
That's fine, if you are ok with a constant jump height.
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« 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
|
|
|
|
Quarry
|
|
« Reply #14 on: October 16, 2012, 05:18:06 AM » |
|
ctrl + h float double
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« Reply #15 on: October 16, 2012, 05:19:51 AM » |
|
I'm not quite sure what that means....
|
|
|
Logged
|
|
|
|
Quarry
|
|
« 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
|
|
« 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
|
|
|
|
Quarry
|
|
« 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
|
|
« 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
|
|
|
|
|