如何判断物体是否处于静止状态?

发布于 2024-11-25 23:47:05 字数 256 浏览 1 评论 0原文

使用物理助手库。

我试图弄清楚如何确定物理对象是否处于静止状态。有谁知道如何做到这一点或对我能做什么有任何想法?

一个示例场景是一个可以捡起并扔来扔去的弹力球。我尝试创建一个计时器,对每个单独的与地板的碰撞事件的弹跳进行计时,并据此确定对象是否处于静止状态,但如果用户将球向左和向右滑动,则这不起作用。

有什么建议吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

错々过的事 2024-12-02 23:47:05

如果您可以在运行时访问底层 Farseer Body,那么您还应该可以访问属性 LinearVelocity,您可以检查该属性的 0 幅度。

If you have runtime access to the underlying Farseer Body, then you also should have access to the property LinearVelocity, which you can check for 0 magnitude.

扛刀软妹 2024-12-02 23:47:05

这是非常基本的东西。你的物理对象应该是某种类的实例,其中包含有关对象的位置、速度等信息。在任何给定时间,你应该能够检查对象的速度,显然如果它的速度 == 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.

疯到世界奔溃 2024-12-02 23:47:05

到目前为止,我已经想出了一个简单的方法。创建两个类变量(Vector2 currentPosition、Vector2 previousPosition),然后创建一个经常滴答的调度程序计时器,并使用以下滴答方法:

void bounceTimer_Tick(object sender, EventArgs e)
    {
        currentPosition = ball.Position;

            if (currentPosition == previousPosition)
            {
                // Object at rest
            }
            else
            {
               // Object moving
            }
        }

        previousPosition = currentPosition;
    }

但它存在一些问题,例如,如果它捕获空中上升的球位置,然后回到同一位置(非常不可能),并且在非常高的滴答频率下,它有时会意外地捕获相同的位置,在缓慢的滴答频率下,需要时间来确定对象是否处于静止状态,其他任何人都有更好的 方法?

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:

void bounceTimer_Tick(object sender, EventArgs e)
    {
        currentPosition = ball.Position;

            if (currentPosition == previousPosition)
            {
                // Object at rest
            }
            else
            {
               // Object moving
            }
        }

        previousPosition = currentPosition;
    }

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文