更改球的方向上高速碰撞基地 [英] Changing the direction of a ball on collision base on speed

查看:176
本文介绍了更改球的方向上高速碰撞基地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个乒乓球比赛。我想创建控制球的基础上对桨的影响方向的能力。如果球灌进在VY = 4; VX = 4;

I am creating a ping pong game. And I want to create the ability to control the direction of the ball based on the impact on the paddle. If the ball is coming down at vy = 4; vx = 4;

和桨被移动到左侧VX = -5;我想球取决于如何快速桨移动稍微改变它的路线。它可能会减少球VX速度上的碰撞,因此使球移动更直(接近Y轴),当它被移动备份。但在此之前我去一个疯狂的尝试和错误的旅程,我想知道是否有人知道答案,或可能有任何的来源。

and the paddle is moving to the left at vx = -5; I want the ball to slightly change its course depending on how fast the paddle is moving. It would probably reduce the balls vx speed on collision, therefore making the ball move more straight (close to the Y axis) when it is moving back up. But before I go on a crazy trial and error journey, I was wanting to know if anyone knew the answer or probably have any sources.

我想的解决方案可能做这将是衡量如何快速的桨是怎么回事。我的问题是该桨叶由鼠标控制的,并且没有一定的速度。我试图找出如何我可以衡量我的鼠标行驶于x轴的速度。

I figure the solution for probably doing this would be to measure how fast the paddle is going. My problem is the paddle is controlled by the mouse and has no certain speed. I am trying to figure out how I can measure the speed of my mouse traveling on the x axis.

我可能会创建一个触发每隔几秒钟,以确定鼠标是和它是一个计时器。图的差,并且将是速度

I am probably going to create a timer that fires every few seconds to determine where the mouse was and where it is at. figure the difference and that will be the speed

如果任何人有任何的答案,这将是巨大的。谢谢

If anyone has any answers, that would be great. thanks

推荐答案

测量挡板的速度,最简单的方法就是保持在previous架挡板的位置的高速缓存,从而通过的x - X $ P $光伏你有桨运动的增量为这个框架,或者相对速度

The easiest way to measure the speed of the paddle is to keep a cache of the position of the paddle in the previous frame, thus by having x - xPrev you have the delta of the paddle movement for this frame, or the relative speed.

从这个速度,你可以将其添加作为改性剂(按比例缩小可能),进了球的反射向量的x速度。

From that speed you can add it as a modifier(scaled down probably), into the x velocity of the ball's reflected vector.

现在这听起来像一个简单的游戏,帧率不应该是一个问题。然而,对于参考,如果你想跟踪速度,简单的物理计算可以通过访问该previous帧的总时间进行。允许一致的行为时,明智的,独立于仿真的帧率。

Now this sounds like a simple game, and framerate should not be a problem. For reference however, if you want to keep track of the velocity, simple Physics calculations could be made by having access to the total time of the previous frame. allowing for consistent behavior time-wise, independent of the framerate of the simulation.

这篇关于更改球的方向上高速碰撞基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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