We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, how can I make an object jump??
Here is what I have made (I want the box to only jump once):
float playerX = 200;
float playerY = 900;
float gravity = 10;
boolean override = true;
void setup() {
size(1000, 1000);
}
void player() {
fill(255, 0, 0);
rect(playerX, playerY, 30, 30);
}
void draw() {
background(255, 255, 255);
player();
if (override == false) {
constrain(playerY, 0, 1000);
}
if (keyPressed == true) {
playerY -= 20;
override = true;
}
if (playerY < 900 && keyPressed == false) {
playerY += gravity;
}
}
Answers
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9LZizxKsIAY4F
Thanks a lot guys!! I was also wondering how I could input this into this code (This is only a snippet):
Shameless self-promotion: I wrote a tutorial on collision detection, including jumping, available here: http://happycoding.io/tutorials/processing/collision-detection
Awesome!!! I still ran into the problem of the fish(character of the game). This is the part I am having trouble:
instead of opening new discussions: try to write a runnable sketch that shows your problem and post this.
the code above is not runnable.
moreover please describe your problem. whats happening now falsely, what do you want it to happen?
jumping: this consists of accelerating in -y direction.
this is then slowed by gravity so that the acceleration gets positive again so the character falls down.
look at the examples, gravity is implemented there and use the idea I laid out
TFguy showed this principle above in his sketch above i think
I have a fish, in water and there is a constraint on it but I need to override the constraint to allow the fish to jump and honestly, I am not sure where to start...
what do you mean by constraint? when he jumps, put the constraint on hold, switch it back on afterwards
Yes