#67425 - deltree - Tue Jan 17, 2006 11:07 pm
Here's a simple code and very smooth to make a character jump:
if (Key.isDown(key.CONTROL) && !jumping)
{
jumping=true;
jump=15;
}
if (jumping)
{
character._y -= jump;
jump -= 1.5;
if (jump<-15) jump = -15; //maximum velocity
}
This is actionscript, from flash, it' easy to translate to C. It's simple, it work very well, and doesn't involve complex operation. It make the character jump and fall properly, with the good acceleration feeling.
#67825 - Palamon - Fri Jan 20, 2006 6:54 pm
I'm about to implement jumping for the first time (right after I put in the floors and how to detect them) and I was going to take a slightly different approach to jumping.
You forgot to mention that you must check to see if the character has landed on solid ground.
Otherwise, you would jump up, the jump would peak, then fall back down, and continue right through the floor and off the bottom of the screen !
The simplest solution, like for a game where you always jump and fall down to the same y coordinate (no jumping to ledges, just dodging things)
is to add a few lines:
if (Key.isDown(key.CONTROL) && !jumping)
{
initial_y = character._y;
jumping=true;
jump=15;
}
if (jumping)
{
character._y -= jump;
jump -= 1.5;
if (jump<-15) jump = -15; //maximum velocity
if (character._y =< initial_y)
{
jumping = false; //turn off falling
character._y = initial_y; //correct so you fall to the exact y as before
jump = 0; //don't really need since you redefine it when you jump again, but I feel better putting it there
}
}
I was planning on making a floor check function to handle if the character is standing on something or is falling or walked off a cliff. This function will increase the downward velocity up to a maxium, or set y velocity to 0 and place y flushly on the floor when hit.
In order to make my character jump, all I would have to do is set the y_veloity to a positive number and let the regular Y = Y + Y_velocity formula and falling function handle the rest.
Jumping graphics would be handled by looking at the sign of the y_velocity variable.
it also might be easier to just incorperate a "character._y_velocity" variable into your structure, instead of the global jump variable (which does the same thing)
#67923 - tepples - Sat Jan 21, 2006 8:37 am
To get good results in jumping physics, you'll need to use fixed-point arithmetic to hold displacements (x, y) and velocities (what you call the "jump" variable).
Yes, you'll need to make a "floor check" function. This will involve reading your collision map structure, which your map editor should have generated, under each of your character's feet.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#68555 - deltree - Wed Jan 25, 2006 5:58 pm
I didn't mention the collision with the ground, because it depends on the way you want it to work.
#68582 - Palamon - Wed Jan 25, 2006 9:38 pm
Besides using collision with the ground or a fixed ending jump height like what I discribed earlier,
What are some other ways to make it work?
#70940 - deltree - Thu Feb 09, 2006 4:41 pm
the character could enter in collision with a wall, or a roof, or a plateform at a different height, or even another character.that's what I meant.
the only thing I wanted to put at light was the code for the global move of the jump. I must add this feature: the smoothiness is far less good on the GBA than the flash version, that's weird.
#70978 - yuriks - Thu Feb 09, 2006 9:13 pm
Maybe because flash has antialiasing? ;)
_________________
---yuriks---
#70990 - deltree - Thu Feb 09, 2006 9:53 pm
yuriks wrote: |
Maybe because flash has antialiasing? ;) |
actually , i'm not talking about "graphics" smoothness, but movement smoothness.
#70993 - yuriks - Thu Feb 09, 2006 10:13 pm
And the two can be linked, if the graphics are jerky, so will be the movement.
The code uses floating point, the gba doesn't do antialiasing.
Look at the following:
In the GBA:
X is 0, displayed X is 0
Add 1.5
X is 1.5, displayed X is 1
Add 1.5
X is 3, displayed X is 3
In Flash:
X is 0, displayed X is 0
Add 1.5
X is 1.5, displayed X is 1, but it is antialiased to 1.5, so it looks smoother.
Add 1.5
X is 3, displayed X is 3.
As you can see graphics smoothness has everything to do with apparent movement smoothness.
In the GBA the X coord jumps from 1 to 3, in Flash the transition is smoothed out by antialiasing.
_________________
---yuriks---