I’m working on a platformer (Mario Bros. esq) and have a question. When character jumps I current have his vertical velocity decreasing as he goes up and then increasing as he comes down. While this seems correct the feel of it is strange. What do most platformer type game do for this?
Hi i think you just need to use acceleration.
Having a accel[4], which contains the acceleration for each direction. Then you can find the resulting movement from the remainder between the 2 opposite accelerations, and at each frame when you process key presses you add the right accel_step to each direction.
int accel_y = acceleration[2] - acceleration[0];
int accel_x = acceleration[1] - acceleration[3];
x += (int)(accel_x * time_step);
y += (int)(accel_y * time_step);
I used this in a space shooter to get a nice accleration feeling. Instead of moving at a constant speed, you accelerate and deccelerate properly.
Hope that helps. Harley.
Assuming that up is positive, you need to start with a high velocity, and decrease it constantly… when it gets to zero that’s when your character is at the top of his jump, and then it will still be decreasing into negative velocity meaning he’ll be starting to come down.
here is my really bad implementation of Mario Bros… it uses very bad system to draw the images but a reasonable movement one although the clipping not too good. (collision detection)
I can’t get the guy to move. I hit the go button and he appeared but then the button retains the focus.
sorry about that, but the keylistener class i made doesnt seem to work in 1.4
i wrote it in java 1.3… anyone know why? also you might try adding that keylistener to the go button if it retains focus, or you could add mainFrame.requestFocus to the go buttons actionlistener but as i dont have 1.4 yet i cant really test this.
edit: x and z for run and jump
i’m going to be rewriting the whole program soon. that file is the final working one, at the moment i have started over entirely.
edit: Ok i installed 1.4 and to fix it temporarily you can modify the line 160: this.addKeyListener(keys);
to go.addKeyListener(keys);
and it works… it’s a little diferent to 1.3, it runs faster…
for those too lazy or cant be bothered editing the source there’s a new reecompiled exe at
http://members.austarmetro.com.au/~juddman/files/java/
you need the zip too - extract it, and copy the fixed exe inside
Thanks for telling him
i’m just wondering, are these .exe files more or less convenient?
double clicking the jar usually does the same as opening the exe without error reporting
ZParticle, i hope this has helped you with your platformer. how far have you got with it? could you post a screenshot? more people should post screenshots of their games to the board.
Well I’ll post post something up when I feel better about it, right now I’m still waiting to see if a number of people that offered to work on the graphics are going to come through or not. I suspect they won’t. The system and the basic game structure are in place and running well I simply need decent graphics and level ideas.
I implemented the jump in the manner you suggested but there is still something about it that bothers me. It just doesn’t feel right where he stops going up and then starts dropping.
Hey check out
http://www.gamedev.net/reference/articles/article437.asp
Its really an old falling body physics question.
The real equation is newSpeed = oldSpeed * vel * time + 1/2 ^a*time2
which is correct but not really useable in the game.
Now this it probally what you have already, but this seems to work.
float up_accel = 0.0f;
if(jump){
up_accel = 1.0f;
jump = false;
}
int y = (int)(py - up_accel * speed);
if(up_accel > 0.0){
up_accel -= gravity;
}
py = y;
you can just tweak gravity and speed to change how fast you go down and up. gravity’s a float 0-1, speed is an it like 8;
Hope that actually helps! Harley.
i admit i am no phycisist, but having the sprite accellerate up off the ground would sort of look like he’s being pulled up on an invisible rope? the accelleration should always be downwards, and the velocity should start at a high number and get set back to zero when he hits the ground.
ZP, what sort of graphics? If it’s a rip off of mariobros, you can use mine if you want or if you tell us a little about the character, the plot, and a bit of other stuff, i could try make up some little sprites and post them. i’ll probably be changing the graphics on my game when it’s finished.
at the moment i have managed to dig out the JLabels and first changed them to JComponents with their own Paint methods, but that didn’t seem much faster than the label, so i’ve started now on working on the paint method of the panel that displays the sprites, adding them to it’s own bufferedimage. it seems a lot faster but there are a few bugs i have to work out like the artifacts left in the wake of any image. ATM my game would not be playable. i am intent on getting the graphics system for it working at a playable level before i start adding anything else to it and it’s a headache.
Juddman and Harley, please join me at www.scottshaver2000.com/forum under the Jumping Jimmy topic. I realy appreciate your input.
I agree with JuddMan. Start with an initial up velocity, say 3 pixels / tick, then decrement it with each tick. Stop falling when your feet collide with something.
ticks | velocity | total up distance
0 0 0
0 3 3
1 2 5
2 1 6
3 0 6 (pauses in midair like Michael Jordan)
4 -1 5
5 -2 3
6 -3 0 (hits the ground)
Rick
Hey, JuddMan an myself are really talking about the same thing. "you need to start with a high velocity, and decrease it constantly… ", i just called it acceleration.
The method i posted actually worked (i tested it with a ball ), but i haven’t made a platformer game. For this application velocity and acceleration are pretty much the same thing. As it isn’t the real equations, but a simplifed version it doesn’t make a difference.
Harley.
Thank you both very much for your input.
At first I was of the impression that an acceleration formula should be used but I’m not so sure any more. Think about this, your character jump off of a high platform. Do we want it to continue to accelerate until it lands or should it max out at about the same velocity as the jump was started at. I think that I would prefer a cap on the character’s fall velocity and I think I’d like a slight hover at the top of a jump. IMO a precalculated jump velocity table would be the way to go. That said, I haven’t written a platformer so I could be wrong, maybe I should refresh my memory: http://www.mame.net/
Another question:
In platformer type games do you all like the idea of a limited time to complete a level or the idea of player lives?
Remember that this is targeted for children.
[quote]do you all like the idea of a limited time to complete a level or the idea of player lives?
[/quote]
Is the level a rich enviroment? If there is little more to do in a level than get through it than a timer would be acceptable, but if there are hidden blocks, items, etc than a time would discourage exploration.
Outside the context of a coin operated game lives don’t serve much of a purpose, plus what’s the point if you can load a saved game. One thing you do see is “continues” which basicly let you resume playing with little loss of progress instead of having to start from the last save point.