help with jumps

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

help with jumps

Post by deathsangel »

can you give me an example of how to make a jump feature?
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: help with jumps

Post by MadPumpkin »

deathsangel wrote:can you give me an example of how to make a jump feature?
dude... specify your language, if your using Macromedia ActionScript2, or AS3 i can pop something out in 2 minutes on a fully working jump, but if its C/++/# you'll have to ask someone else i cant do any graphical C/++/# only console
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

Re: help with jumps

Post by deathsangel »

Im using c++ and sdl
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine :)
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: help with jumps

Post by MadPumpkin »

deathsangel wrote:Im using c++ and sdl
then well... i can't help very much, although it could be very similar to AS jump movement if you would like me to put it up
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: help with jumps

Post by thejahooli »

it would be the same really for any language and API as the concepts would be the same.

Also how realistic do you want it to be? Because I could probably think up a very unrealistic jump that would look rubbish but I wouldn't be able to make a decent one
I'll make your software hardware.
User avatar
Spikey
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Sat Dec 13, 2008 6:39 am
Programming Language of Choice: C++
Location: Ottawa, Canada
Contact:

Re: help with jumps

Post by Spikey »

Regardless of language, this will work.
Make your object have a velocity in which is updated onto object's position every tick/update.
To jump, add a Y+ velocity, say +20.
Then every tick, apply gravity, say -9
check for floor collision to stop fall. You can also do things like terminal fall velocity, ie) if Y_Velocity < -20 then Y_Velocity = -20
Also depending on the frame rate or based how objects are updated you might need to scale everything down. Y_Position += Y_Velocity * SCALE
deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

Re: help with jumps

Post by deathsangel »

right now my jump code looks like this

Code: Select all

void jump()
{
	// decide if the player can or cant jump  
	if (can_jump)
	{
		// set it to false so that you cannot double jump
		can_jump = false;

		// move the player up 70 pixels
		Player1.set_y(Player1.get_y() - 70);
	}
}
can jump is set to true when there is a collision with a tile

how can I make it a more smooth jump so that he does not just "teleport" to the location
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine :)
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: help with jumps

Post by MadPumpkin »

Heres a cute little jump code i picked up a while back for AS2 possibly someone can just skrew around with it and make it C++ style

Code: Select all

if (speed<1 && speed>-1) {
   speed = 0;
}
if (Key.isDown(Key.UP) && !jumpness) {
   jumpness = true;
}
if (jumpness) {
   this._y -= jump;
   jump -= .5;
   if (jump<0) {
   falling = true;
}
if (jump<-10) {
   jump = -10;
}
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

Re: help with jumps

Post by deathsangel »

Ive updated my jump code! Now it looks better, but not perfect :( can you help me improve it?

Code: Select all

void jump()
{
	if (can_jump)
	{
		can_jump = false;

		jumpY = Player1.get_y() - 90;
		jumped = true;
	}

	if (jumped)
	{
		if (Player1.get_y() > jumpY)
			Player1.set_y(Player1.get_y() - 3.0f);

		else
			jumped = false;
	}
}
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine :)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: help with jumps

Post by MarauderIIC »

You forgot to reset can_jump to true.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

Re: help with jumps

Post by deathsangel »

actually that happens when there is collision between the player and the top of a tile.
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine :)
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: help with jumps

Post by eatcomics »

Doesn't this code just make him warp to the jump height, then warp to the ground again????
Image
deathsangel
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Apr 18, 2009 8:17 pm

Re: help with jumps

Post by deathsangel »

nope it works like this

1) if the user cannot jump skip the function
2) if the user can jump then set can jump to false
3) this way he cannot jump again until he touches the ground
4) set the jump coordinate to 90 pixels above the user
5) while the user is holding down the jump key(space)
a) move the player to the jump coordinate
b) check where the player is
6) if the player is at the jump coordinate stop jumping and allow gravity to take over...

However this does not work to well because the user can keep jumping as long as he does not go above the jump coordinate
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine :)
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: help with jumps

Post by eatcomics »

deathsangel wrote:nope it works like this

1) if the user cannot jump skip the function
2) if the user can jump then set can jump to false
3) this way he cannot jump again until he touches the ground
4) set the jump coordinate to 90 pixels above the user
5) while the user is holding down the jump key(space)
a) move the player to the jump coordinate
b) check where the player is
6) if the player is at the jump coordinate stop jumping and allow gravity to take over...

However this does not work to well because the user can keep jumping as long as he does not go above the jump coordinate
ahh, i see now ;)
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: help with jumps

Post by MarauderIIC »

So you need to make it so they 'can't jump' once they reach the jump height.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply