玩家跌落系统(基本上是重力) [英] A player-falling system (basically gravity)

查看:133
本文介绍了玩家跌落系统(基本上是重力)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一款类似于Doodle Jump的游戏,让你的玩家尽可能高。现在,我让我的播放器工作,并移动。但是,问题是,我没有引力,或任何会让玩家再次摔倒在地的东西。你们有没有想过这样做?我试着让玩家得到一个恒定的力量,一直被推下来,但是,它不是很平滑,而且它不像真正的摔倒。我可以帮助制作这个玩家掉落系统吗?

I am making a game that is similar to Doodle Jump, getting your player as high as possible. Now, I got my player working, and moving. But, the problem is, I don't have gravity, or anything that will make the player fall down onto the ground again. Do you guys have any idea of doing this? I tried having the player get a constant force, being pushed down at all times, but, it's not smooth, and it doesn't act like real falling. Can I have some help with making this player-falling system?

编辑:

    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 made this, didn't work, shoots my player up in the air.

推荐答案

在现实世界中,重力会随着时间的推移而增加一个恒定的速度(每秒9.8米<强>每秒)。您可以通过给予玩家垂直速度(当他们跳跃或从平台上掉下来)然后每次围绕主游戏循环从该值中减去一个恒定量来模拟这一点,以便它们随着时间的推移而加速。你需要对此(最终速度)设置一个最大限制,否则当它们长时间落下时它们可能会很快达到可笑的速度。伪代码看起来像这样:

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

编辑每秒9.8米每秒是正确的!请不要编辑它!加速度是指速度随时间的变化,以米/秒/秒表示。每秒9.8米每秒意味着静止物体在1秒后将加速到足以以9.8米/秒的速度行进。 2秒后,它将达到19.6米/秒的速度。 3秒后它将达到29.4米/秒的速度,依此类推。

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.

这篇关于玩家跌落系统(基本上是重力)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆