当 shouldEnableLimits 为 true 并且设置了 lowerAngleLimit 和 upperAngleLimit 时,SKPhysicsJointPin 的行为不正确 [英] Incorrect behaviour with SKPhysicsJointPin when shouldEnableLimits is true and lowerAngleLimit and upperAngleLimit set

查看:16
本文介绍了当 shouldEnableLimits 为 true 并且设置了 lowerAngleLimit 和 upperAngleLimit 时,SKPhysicsJointPin 的行为不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个布娃娃图,它由一个父节点(没有附加物理体)和许多子节点组成,每个子节点都由一个圆形体组成.圆圈之间使用 SKPhysicsJointPin 相互连接,如下所示:

I currently have a ragdoll figure, which consists of a parent node (with no physics bodies attached), and lots of child nodes which each consist of a circle body. The circles are connected to each other using an SKPhysicsJointPin between each circle, as so:

每个 SKPhysicsJointPin 都有 shouldEnableLimits = true,我目前为 lowerAngleLimitupperAngleLimit<使用 -0.05 和 0.05 的值/code> 分别.

Each SKPhysicsJointPin has shouldEnableLimits = true, and I currently use a value of -0.05 and 0.05 for lowerAngleLimit and upperAngleLimit respectively.

这很有效,并且可以防止形状过度变形,除非整个人像上下颠倒,在这种情况下,所有关节都会突然尝试收缩,如下所示:

This works pretty well and prevents the shape from deforming too much, except when the figure goes upside-down as a whole, in which case all the joints suddenly try to contract, like so:

当人偶完全倒置时,关节会很快收缩.当他再次旋转回来时,所有关节都恢复正常.为什么会这样?如何保持关节的正确角度?

The joints contract very quickly about when the figure is completely upside down. When he rotates back again, all the joints return to normal. Why does this happen? How do I maintain the correct angles on the joints?

编辑 1:

我只是尝试用 Objective-C 重写项目,以防它是由于一些奇怪的 Swift 错误造成的;事实证明这个问题仍然在 Objective-C 中表现出来,所以我删除了 Swift 标签.

I just tried rewriting the project in Objective-C in case it was due to some weird Swift bug; turns out this problem still manifests itself in Objective-C, so I've removed the Swift tag.

目前我最好的猜测是,当它们连接的物体在任一方向上旋转超过 180° 时,SpriteKit 会错误地计算关节相对于世界的角度,因此会出现错误的角度传递给底层的 Box2D 关节.

My best guess at the moment is that the angle of the joints, relative to the world, are incorrectly calculated by SpriteKit when the bodies they are attached to are rotated more than 180° in either direction, and so wrong angles are being passed to the underlying Box2D joints.

我不确定我是否应该不断更新上下角度限制以匹配他们身体的世界角度,但我似乎不必这样做,因为当身体非常接近向上时- 下做关节停止正常工作.无论如何,我会继续尝试……

I wasn't sure if I was supposed to continuously update the lower- and upper-angle limits to match their bodies' world angles, but it doesn't seem I have to as when the body is very close to being upside-down do the joints stop working properly. I'm going to keep experimenting, anyway…

编辑 2:

我现在相当确定问题的发生是因为 SpriteKit 正在(我猜有充分的理由)修改 zRotation 值以使其保持在 -180° 和 180° 之间.例如,如果节点顺时针旋转并达到 -180°,SpriteKit 会自动将其值回绕到 +180°.我相当有信心这种环绕会导致关节行为不正常,我只需要弄清楚如何抵消它......

I'm now fairly sure that the problem occurs because SpriteKit is (I guess with good reason) modifying the zRotation value to keep it between -180° and 180°. If for example the node is rotating clockwise and it hits -180°, SpriteKit automatically wraps its value back to +180°. I'm fairly confident this wrap-around is causing the joints to behave erratically, I just need to figure out how to counteract it…

编辑 3:

我已经上传了演示此问题的示例应用程序(包括视频),正如 Apple 最初要求的那样:Xcode 项目/视频

I've uploaded the sample application (including video) which demonstrates this problem, as originally asked for by Apple: Xcode Project / Video

推荐答案

我可以确认,这是 SpriteKit 中的一个错误.在我的例子中,我使用的是最简单的两个精灵通过销接头连接的场景.不幸的是,它仍在 iOS 9 上发生 :(

I can confirm, that this is a bug in SpriteKit. In my case I'm using the simplest scenario of two sprites joined by pin joint. Unfortunately it's still happening on iOS 9 :(

这篇关于当 shouldEnableLimits 为 true 并且设置了 lowerAngleLimit 和 upperAngleLimit 时,SKPhysicsJointPin 的行为不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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