Opengl java 弹跳实体

你好,这实际上是我在这里的第一个问题..我一直在开发一个 opengl lwjgl 游戏,我正在研究实体类。我已经完成了使实体跳转(不适用于动物)但是“问题”(99.9 % 确定这是我的错)是每次实体接触地形并再次跳跃时,跳跃更高,如我录制的视频中所示,这是跳跃的代码 thz =DI 只是希望树始终向上移动。

    double velocity = 0;

double initVelX;

double initVelZ;

double time = 0;

float x;

float y;

float z;


public void bounce() {


    double initialVelocity = 0.1;       

    double speed = 1/2500.0;


    if(time == 0) {

        velocity += initialVelocity;

    }

    time += speed;

    velocity = velocity - 9.8 * speed;

    if(y + velocity < 0.1){

        velocity *= -1;

    }

    y += velocity;

    setPosition(new Vector3f(getPosition().x,y,getPosition().z));

}


SMILET
浏览 112回答 2
2回答

largeQ

修复它只需要做一行简单的代码,它甚至可以正确地调整速度波动:double velocity = 0;&nbsp; &nbsp; double initVelX;&nbsp; &nbsp; double initVelZ;&nbsp; &nbsp; double time = 0;&nbsp; &nbsp; float x;&nbsp; &nbsp; float y;&nbsp; &nbsp; float z;&nbsp; &nbsp; public void bounce() {&nbsp; &nbsp; &nbsp; &nbsp; double initialVelocity = 0.1;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; double speed = 1/2500.0;&nbsp; &nbsp; &nbsp; &nbsp; if(time == 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velocity = initialVelocity;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; time += speed;&nbsp; &nbsp; &nbsp; &nbsp; velocity = velocity - 9.8 * speed;&nbsp; &nbsp; &nbsp; &nbsp; if(y + velocity < 0.1){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velocity *= -1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; velocity = initialVelocity;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; y += velocity;&nbsp; &nbsp; &nbsp; &nbsp; setPosition(new Vector3f(getPosition().x,y,getPosition().z));&nbsp; &nbsp; }

米琪卡哇伊

我认为这将是这些增量语句之一:velocity += initialVelocity;time += speed;velocity *= -1;y += velocity;您是否希望所有这些都不断上升?因为这就是会发生的事情。你的代码的哪一部分计算了跳跃的高度?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java