如何判断物体是否处于静止状态?
使用物理助手库。
我试图弄清楚如何确定物理对象是否处于静止状态。有谁知道如何做到这一点或对我能做什么有任何想法?
一个示例场景是一个可以捡起并扔来扔去的弹力球。我尝试创建一个计时器,对每个单独的与地板的碰撞事件的弹跳进行计时,并据此确定对象是否处于静止状态,但如果用户将球向左和向右滑动,则这不起作用。
有什么建议吗?
Using the physics helper library.
I'm trying to figure out how I can determine whether a physics object is at rest. Does anyone know how to do this or have any ideas of what I could do?
An example scenario is a bouncy ball that can be picked up and thrown around. I tried creating a timer that times each individual bounce from a collision event with the floor and determines if the object is at rest based off of that but this does not work for if the user slides the ball to the left and right.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以在运行时访问底层 Farseer
Body
,那么您还应该可以访问属性LinearVelocity
,您可以检查该属性的0
幅度。If you have runtime access to the underlying Farseer
Body
, then you also should have access to the propertyLinearVelocity
, which you can check for0
magnitude.这是非常基本的东西。你的物理对象应该是某种类的实例,其中包含有关对象的位置、速度等信息。在任何给定时间,你应该能够检查对象的速度,显然如果它的速度 == 0 ,它处于静止状态。
This is pretty basic stuff. Your physics object should be an instance of some kind of class which contains information on the object's position, velocity, etc etc. At any given time, you should be able to check the speed of the object, and obviously if its speed == 0, it is at rest.
到目前为止,我已经想出了一个简单的方法。创建两个类变量(Vector2 currentPosition、Vector2 previousPosition),然后创建一个经常滴答的调度程序计时器,并使用以下滴答方法:
但它存在一些问题,例如,如果它捕获空中上升的球位置,然后回到同一位置(非常不可能),并且在非常高的滴答频率下,它有时会意外地捕获相同的位置,在缓慢的滴答频率下,需要时间来确定对象是否处于静止状态,其他任何人都有更好的 方法?
So far I've came up with a simple method. Creating two class variables (Vector2 currentPosition, Vector2 previousPosition) and then creating a dispatcher timer that ticks every so often and using the following tick method:
There are some issues with it though for example if it captures the balls position in the air coming up and then back down at the same position (very unlikely) and at a very high frequency in ticking it can sometimes capture the same position unexpectedly, at a slow frequency of ticking it takes time to determine if the object is at rest, anyone else have a better method?