It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
我正在实现使用重力的游戏,但是我不知道如何模拟球的重力。

我有一个计时器,当我“放下”球后立即开始计时,我必须设置目标球的垂直位置。

相关功能包括:

int ball->setVerticalPosition(int Y);
float timer->getTime();


谢谢!

最佳答案

好的,通常,您可以使用以下公式计算新位置(pos_y):

t = timer->getTime();
float pos_y = pos_y0 + v_0*t - 4.9 * t *t;
ball->setVerticalPosition(pos_y);


(v_0是初始速度,而pos_y0是球的初始坐标)。在您的情况下,您说您正在“丢球”,所以如果删除v_0 * t,可能会更好。 pos_y0是原始高度(取决于坐标系)。

别忘了检查pos_y = 0的时间(可能是您所在的楼层!)

关于c++ - 球的重力模拟,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13742519/

10-10 00:06