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

查看:115
本文介绍了当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的值.

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?

我只是尝试用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.

此刻,我的最佳猜测是SpriteKit不正确地计算了关节相对于世界的角度,这是因为它们所附着的物体在任一方向上旋转了180°以上,因此出现了错误的角度传递给基础的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…

我现在非常确定会出现问题,因为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要求:视频

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天全站免登陆