In order to make something simply jump would I use a parabola or something simpler?
public class JumpingThing {
// You might want to play around with this:
public static final float METER_TO_PIXELS = 32f;
public static final float SECONDS_TO_FRAMES = 1f / 60f;
// 9.81 [m/s²] is the average ground factor on earth. This is the value to play around,
// if you want the game to play on the moon, for example
public static final float GRAVITY = 9.81f * METER_TO_PIXELS * SECONDS_TO_FRAMES;
// Play around with this value as well:
public static final float JUMP_POWER = 10f; // The higher this value, the higher (stronger) it jumps.
// Usually you'd also have X position and so on, but I leave it out, since it's only going up or down
private float velocityY;
private float positionY;
public void update() {
// Make the object accelerate towards the bottom
velocityY += GRAVITY;
// If you use this method names I'll kill you :P
if (thisThingWantsToJump() && thisThingIsAbleToJump()) {
// It's minus, because it's going down, not up.
// Remove the minus, when you have your y values
// increasing to the top.
velocityY = -JUMP_POWER;
}
positionY += velocityY;
}
} // That's it!
http://lmgtfy.com/?q=jumping+in+java
Seriously, you needed to create a new thread for this? There are countless examples and explanations online and even here on this forum.
I hate lmgtfy links, but basically you’re right.
Seriously?
Edit: Ninja’d. Search for gravity in games or something.
This endless parade of really basic questions is really starting to wear on people here. You need to do some really basic research first, and if you’re still stuck, flesh out your questions with something you’ve already tried. Show a little effort.
I suppose you are right about that, i try and learn things quickly and often dont find results as quickly as I want so I come here… I will start spending more time researching from now on
Now, did my post help you, at least?
I have not tried it yet but should velocityY += GRAVITATION; in the second line of the update method be velocityY += GRAVITY; ?
Yes. sorry, typo fixing it
Thanks it works great! i now know I shouldnt ask things like this here
Also, this is wrong forum section. Should be Newbie Questions :point:
Hmmm?? maybe wreed12345 doesent like doing his homework… :o