Page 1 of 2
help with jumps
Posted: Sun Apr 19, 2009 8:06 pm
by deathsangel
can you give me an example of how to make a jump feature?
Re: help with jumps
Posted: Sun Apr 19, 2009 9:49 pm
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
Re: help with jumps
Posted: Sun Apr 19, 2009 11:31 pm
by deathsangel
Im using c++ and sdl
Re: help with jumps
Posted: Mon Apr 20, 2009 10:40 am
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
Re: help with jumps
Posted: Mon Apr 20, 2009 11:45 am
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
Re: help with jumps
Posted: Mon Apr 20, 2009 1:23 pm
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
Re: help with jumps
Posted: Mon Apr 20, 2009 7:36 pm
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
Re: help with jumps
Posted: Tue Apr 21, 2009 1:02 am
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;
}
Re: help with jumps
Posted: Tue Apr 21, 2009 10:18 pm
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;
}
}
Re: help with jumps
Posted: Wed Apr 22, 2009 6:08 pm
by MarauderIIC
You forgot to reset can_jump to true.
Re: help with jumps
Posted: Wed Apr 22, 2009 7:26 pm
by deathsangel
actually that happens when there is collision between the player and the top of a tile.
Re: help with jumps
Posted: Fri Apr 24, 2009 6:29 pm
by eatcomics
Doesn't this code just make him warp to the jump height, then warp to the ground again????
Re: help with jumps
Posted: Sat Apr 25, 2009 3:46 pm
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
Re: help with jumps
Posted: Sat Apr 25, 2009 4:03 pm
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
Re: help with jumps
Posted: Sun Apr 26, 2009 4:44 pm
by MarauderIIC
So you need to make it so they 'can't jump' once they reach the jump height.