如何有效使用“deviceMotion” CMMotionManager 强制球在圆形边界内移动?

发布于 2024-12-01 12:12:50 字数 403 浏览 10 评论 0原文

我正在使用Chipmunk Space Manager。 我的空间设置是由一个球和一堆线段(在我的例子中为 512 个)连接在一起形成一个圆圈。

我的目标是当用户移动设备时迫使球在该圆圈内移动。 用户移动设备的速度越快,球绕圈移动的速度就越快。球也必须遵循所有物理定律。

我从 CMMotionManager 获取重力和 userAcceleration 组件,但无法理解它。

我尝试手动施加力,这确实有效,但我无法根据用户移动设备的程度来移动圆圈中的球。 就像我将一个小球放入玻璃杯中并摇动玻璃杯一样,当不再有外力移动/倾斜玻璃杯时,球会在玻璃杯的圆形底部移动,并沿玻璃杯倾斜的方向静止。

I am using Chipmunk Space Manager.
I have my space setup with one ball and a bunch of segments (512 in my case) joined together to make a circle.

My aim is to force the ball to move in that circle as user moves the device.
The faster user moves the device, faster the ball will move in circle. The ball has to follow all physical laws as well.

I am getting gravity and userAcceleration components from CMMotionManager but unable to make some sense out of it.

I tried applying force manually and that works realistically, but I am unable to move the ball in the circle depending on how much user moved the device.
Like if I put a small ball in a glass and shake the glass, the ball will move in the circular bottom of the glass and comes to rest in the direction of tilt of glass when there is no more external force moving/tilting the glass

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

白云不回头 2024-12-08 12:12:50

我认为最简单的方法就是改变空间的重力以匹配加速度计。为了获得平滑的圆周运动,最好使用 cpSlideJoint,其最小距离为 0,最大距离为要旋转的圆的半径。否则不可能制作平滑的空心形状。您必须用许多线段来构建它,这可能不会很好地工作。

I think the easiest way to do it would just be to change the gravity of the space to match the accelerometer. To get smooth circular motion it would probably be best to use a cpSlideJoint with a min dist of 0 and a max dist of the radius of the circle you want to spin it in. It's not possible to make a smooth hollow shape otherwise. You'd have to build it out of many line segments and that might not work very well.

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