Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 精灵从屏幕顶部坠落,重力加速度为普通js_Javascript_Math_Game Physics_Mathematical Optimization - Fatal编程技术网

Javascript 精灵从屏幕顶部坠落,重力加速度为普通js

Javascript 精灵从屏幕顶部坠落,重力加速度为普通js,javascript,math,game-physics,mathematical-optimization,Javascript,Math,Game Physics,Mathematical Optimization,嗨,我正试着把怨恨从屏幕的顶部移到底部。我想达到一种类似重力的效果。为了防止人们建议使用游戏引擎,a:这个js在node.js服务器上运行,而不是在客户端上运行(你可以建议node使用游戏引擎),B:这是我唯一需要使用重力效果的地方,所以我觉得只需在里面做一个带有某种加速计算的循环就更简单了 在这个例子中,除了计算之外,我不需要做任何事情 var theMeteor = { "x":500, //the start x position "y":1000, //the start y posit

嗨,我正试着把怨恨从屏幕的顶部移到底部。我想达到一种类似重力的效果。为了防止人们建议使用游戏引擎,a:这个js在node.js服务器上运行,而不是在客户端上运行(你可以建议node使用游戏引擎),B:这是我唯一需要使用重力效果的地方,所以我觉得只需在里面做一个带有某种加速计算的循环就更简单了

在这个例子中,除了计算之外,我不需要做任何事情

var theMeteor = {
"x":500, //the start x position
"y":1000, //the start y position
"v":1 // the velocity
};

function MeteorFall(dt){

theMeteor.y += (theMeteor.v * dt) * -1; // move the meteor down
theMeteor.v++;// increase the velocity

// keep looping until its at the bottom
if(theMeteor.y <= 0){
// its at the bottom so clear the loop
clearInterval(theDeamon);
}

}

var dt = 0.025; //set this to whatever the loop refreshes at (0.025 = 25)
var theDeamon = setInterval(MeteorFall, 25, dt);
var themeter={
“x”:500,//起始x位置
“y”:1000,//起始y位置
“v”:1//速度
};
功能性流星雨(dt){
theMeteor.y+=(theMeteor.v*dt)*-1;//向下移动流星
themeter.v++;//增加速度
//继续循环,直到它在底部

如果(Themeter.y)哪一部分“不是很好,”你在当前的实现中遇到了什么问题?我如何将加速度降低一点,或者像节流阀一样使它看起来更真实。它开始时非常慢,速度非常快,速度非常快。我希望它尽可能地模拟重力改变速度和加速度之间的关系。我改变了这个;theMeteor.v++;对于这个-theMeteor.v++=1.5-似乎足够了。@DavidColeman为什么不
theMeteor.v++=9.81*dt;
其中9.81是地球表面的重力加速度,单位为
[m/s^2]
如果使用不同的国际单位,则将数值转换为您的单位…参见这些:和