help with jumps
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
help with jumps
can you give me an example of how to make a jump feature?
- MadPumpkin
- 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
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 consoledeathsangel wrote:can you give me an example of how to make a jump feature?
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
For God so loved the world that he blessed the thugs with rock
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
Re: help with jumps
Im using c++ and sdl
Thanks to gyro vorbis for inspiring me to learn how to make a 2d graphics engine
- MadPumpkin
- 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
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 updeathsangel wrote:Im using c++ and sdl
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
For God so loved the world that he blessed the thugs with rock
- thejahooli
- Chaos Rift Junior
- Posts: 265
- Joined: Fri Feb 20, 2009 7:45 pm
- Location: London, England
Re: help with jumps
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
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.
- Spikey
- 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
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
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
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
Re: help with jumps
right now my jump code looks like this
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
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);
}
}
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
- MadPumpkin
- 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
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
For God so loved the world that he blessed the thugs with rock
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
Re: help with jumps
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
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: help with jumps
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.
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
Re: help with jumps
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
Re: help with jumps
Doesn't this code just make him warp to the jump height, then warp to the ground again????
-
- Chaos Rift Newbie
- Posts: 30
- Joined: Sat Apr 18, 2009 8:17 pm
Re: help with jumps
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
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
Re: help with jumps
ahh, i see nowdeathsangel 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
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: help with jumps
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.