在施加力之前绘制抛射体的点
例如,在 Peggle 或 Apple Jack 中,用户可以围绕一条曲线移动,该曲线显示在用户请求发射射弹之前球(或洗衣机/熊猫或其他物体)即将到达的位置。我知道我需要使用方程来绘制点,但我不再是数学家了:()。任何人都可以好心地为我提供正确的方程并告诉我应该替换什么来得到我的 X 任意值吗?给定一定时间和初始速度的 Y 值。
For example in Peggle or Apple Jack, the user can move around a curve showing where the ball (or the washing machine / panda or whatever) is about to go before the user has requested that the projectile is launched. I know i need to use an equation to plot the points but I'm no mathematician (anymore :(). Can anybody be so kind as to provide me with the correct equation and tell me what I should substitute in to get my X any Y values given a certain time and initial velocity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看我对这个问题的回答。
根据该答案,您应该使用的公式是:
(位移等于:初始位移,加上初始速度乘以时间,加上半加速度乘以时间平方。)
除了时间之外的所有内容都有一个向量(加速度将是你向下的重力)。因此,只需在 X 轴和 Y 轴上使用该方程即可。
当然,保证绘制的路径与您的预测方程完全匹配的唯一方法是它们是否相同。这是我认为您可以添加对预测跳出的支持的唯一方法。
如果您的实际游戏使用不同的东西(例如完整的物理模拟器),并且您不需要预测弹跳,并且不必完全准确 - 那么这将为您提供合适的预测近似值。
Take a look at my answer to this question.
Taken from that answer, the formula you should be using is:
(Displacement equals: initial displacement, plus initial velocity multiplied by time, plus half acceleration multiplied by time squared.)
Everything except time there is a vector (acceleration will be your downwards gravity). So simply use that equation on both your X and your Y axis.
Of course - the only way to guarantee that the plotted path will match your prediction equation exactly is if they are the same. That is the only way I can see for you to add support for predicting bounces.
If your actual game uses something different (like a full physics simulator), and you don't need to predict bounces, and you don't have to be perfectly accurate - then this will give you a suitable approximation for the prediction.
模拟可能是最简单的路线:创建一个具有指定属性的虚拟对象,并创建一个循环来应用力,并将位置输出到数组,然后显示它,例如:绘制位置之间的一条线或在每个位置绘制射弹的“幽灵”。
模拟的一个优点是您可以通过更改记录位置的频率来控制速度和准确性的平衡。
Simulation would probably be the easiest route to go down: create a dummy object with the specified properties and create a loop to apply the forces and say output the positions to an array and then display it, say: draw a line between the positions or draw a "ghost" of the projectile at each position.
A positive thing about simulation is you can control the balance of speed and accuracy by changing how often you record the positions.
如果这是一个遵循简单弹道轨迹的射弹,您可以使用此处提供的封闭式表达式:
http: //en.wikipedia.org/wiki/Trajectory_of_a_projectile
如果没有,在每个(小)时间步长模拟所有力对身体的影响,相应地更新其位置和速度可能会简单得多。该技术更加稳健;您可以在不改变基本方法的情况下增加问题的复杂性。
If this is a projectile following a simple ballistic trajectory, you can use the closed-form expressions provided here:
http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
If not, it might be a lot simpler to simulate the effect of all the forces on the body for each (small) time-step, updating its position and velocity accordingly. This technique is more robust; you can add a lot more complexity to the problem without changing the basic methodology.
您可以使用牛顿法约。解决。这里的问题是您需要积分 - 因此您必须定义精确度和计算时间之间的权衡。
RK4 是我认为最好的方法 - 它快速且仍然非常精确。
您可以在 http://gafferongames.com/game-physicals/integration-basics 阅读更多信息/
You could use newton's method of approx. solving. The problem here is that you need to integrate - so you have to define the trade-off between preciseness and calculation time.
RK4 is the method that is best in my opinion - it is fast and still very precise.
You can read more info at http://gafferongames.com/game-physics/integration-basics/