Java – a system that players drop (basically gravity)

I'm making a game like Doodle Jump to make your players as high as possible Now I let my player work and move But the problem is, I don't have gravity, or anything that will make the player fall to the ground again Have you ever thought about doing this? I try to give players a constant force and keep being pushed down, but it's not very smooth and it's not like a real drop Can I help make this player drop 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. It's no use. Play my player in the air

Solution

In the real world, gravity will increase a constant rate of decline over time (9.8 meters per second) You can simulate this by giving players vertical speed (when they jump or fall off the platform) and then subtracting a constant amount from this value each time around the main game cycle so that they accelerate over time You will want to set a maximum limit on this (final speed), otherwise they may quickly reach ridiculous speed when they fall for a long time The pseudo code looks like this:

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;
    }
}

Editor: 9.8 meters per second is correct! Please do not edit it! Acceleration is measured as the change of speed with time, expressed in meters / seconds / seconds 9.8 meters per second means that a stationary object will accelerate enough to travel at a speed of 9.8 meters per second in one second After 2 seconds, it will reach a speed of 19.6 M / s After 3 seconds, it will reach a speed of 29.4 M / s, and so on

To be honest, I don't believe it. I even have to explain

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>