Player crash system (mainly gravity)

I am making a game similar to Doodle Jump, getting the player as high as possible. Now I have earned my player and am moving. But the problem is that I don’t have gravity or anything else that will make the player fall to the ground again. Do you guys have an idea about this? I tried to ensure that the player had a constant force, pushed all the time, but it is not smooth, and it does not act like a real drop. Can I provide some help in creating this player crash system?

Edit:

    GRAVITY = 10;
    TERMINAL_VELOCITY = 300;
    vertical_speed = 0;

    public void fall(){ 
    this.vertical_speed = this.vertical_speed + GRAVITY;
    if(this.vertical_speed > TERMINAL_VELOCITY){
        this.vertical_speed = TERMINAL_VELOCITY;
    }
    this.y = this.y - this.vertical_speed;
}

I did this, did not work, shoots my player in the air.

+3
source share
6 answers

(9,8 ). , ( ), , . ( ), , , . :

const GRAVITY = 10;
const TERMINAL_VELOCITY = 300;

object Player 
{
    int vertical_speed = 0;
    int vertical_position;  

    function fall ()
    {
        this.vertical_speed = this.vertical_speed + GRAVITY;
        if (this.vertical_speed > TERMINAL_VELOCITY)
        {
            this.vertical_speed = TERMINAL_VELOCITY;
        }
        this.vertical_position = this.vertical_position - this.vertical_speed;
    }
}

: 9,8 ! ! , . 9,8 , 1 , 9,8 /. 2 19,6 /. 3 29,4 / .

, .

+7

?

velocity = acceleration * time

acceleration - .

time - .

,

distance = 1/2 * acceleration * time**2
+4

:

       g * t ^ 2
s(t) = --------- + v * t + h
           2    

s - (time - height), g - (9,8 ), v - , h - .

+1

, , , , .

0. , .

:

- :

if (stillFalling) {
    velocity = velocity + (gravity_constant) * time_interval;
} else {
    velocity = 0;
}

.

0

-. , , wiki .

0

- .

public void run() {
    if(velY+g>TerminalVel) {
        velY=TerminalVel;
    } else {
        velY+=g; 
    }
    y+=velY;
}

run() .

0

All Articles