3

Doodle Jump に似たゲームを作成して、プレイヤーをできるだけ高くします。今、私は自分のプレーヤーを動作させ、動かしました。しかし、問題は、私には重力がなく、プレイヤーを再び地面に倒せるものがないということです。皆さん、これを行う考えはありますか? プレイヤーに一定の力を加えて、常に押し倒してみましたが、滑らかではなく、実際の落下のようには動作しません。このプレイヤーが落ちるシステムを作るのを手伝ってもらえますか?

編集:

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

私はこれを作りましたが、うまくいきませんでした。プレーヤーを空中に撃ち落としました。

4

6 に答える 6

9

In the real world gravity will increase the rate of a fall by a constant amount over time (9.8 meters per second per second). You could simulate this by giving the player a vertical speed (when they jump or fall off a platform) and then subtracting a constant amount from that value every time round the main game loop so that they accelerate over time. You'll want to put a maximum limit on this (terminal velocity) otherwise when they fall a long way they could hit ludicrous speed fairly quickly. The pseudo-code would look something 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;
    }
}

EDIT: 9.8 Metres Per Second Per Second is correct! Please don't edit it! Acceleration is measured as change in velocity over time, expressed in metres per second per second. 9.8 meters per second per second means that after 1 second a stationary object would have accelerated enough to be travelling at 9.8 m/s. After 2 seconds, it will have attained a speed of 19.6 m/s. After 3 seconds it will have attained a speed of 29.4 m/s and so on.

I honestly don't believe I even had to explain that.

于 2011-05-24T14:07:11.747 に答える
5

重力の公式を知っていますか?

velocity = acceleration * time

acceleration重力加速度です。

time経過時間です。

また、

distance = 1/2 * acceleration * time**2
于 2011-05-24T14:02:16.900 に答える
2

任意の時点で重力のあるエンティティの高さを計算する式は次のようになります。

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

ここsで、 は時間の関数 ( timeheight)、gは重力係数 (メートルの場合は 9.8)、vは元の上向き速度、hは元の高さです。

于 2015-08-24T16:13:58.567 に答える
0

人に一定の力を作用させる代わりに、落下中に人を加速させる必要があります。

それらは0速度とともに落下し始めるはずです。次に、落下するときに力を増やす必要があります。

これを行うには、時間をかけて速度を更新する必要があります。

このようなもの:

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

速度を継続的に更新する必要があります。

于 2011-05-24T14:03:26.693 に答える
0

その Web サイトで説明とデモを見つけることができます。また、物理学に関する本を読むか、少なくとも重力に関する wiki 記事を読むことをお勧めします。

于 2011-05-24T14:03:37.927 に答える