当与其他精灵相撞时,如何防止使用物理机体移动Skspritenode



我有两个Skspritenodes,假设一个代表棒球棒,另一只是球。两者都有物理体,碰撞效果很好,或者至少检测到。我有一个滑动蝙蝠的滑动,它与球碰撞。发生这种情况时,他们俩都开始移动。我希望球飞走,蝙蝠留在原地。我该如何实现?谢谢!

尝试制作 bat.physicsBody.dynamic = false,或者使蝙蝠不会与球相撞(但要保持球与蝙蝠相撞),即蝙蝠的collisionBitMask不包含球的categoryBitMask

bat.physicsBody?.collisionBitMask &= ~ballCategory // bat does not collide with ball

如果您想在球击球时停止蝙蝠,则必须做一些骗局(例如,在两者之间和触摸之间建立触点,删除蝙蝠上的动作和/或将蝙蝠的速度设置为0)。

好的,显然很容易 - Skphysicsbody上有一个pinned属性,我只需要将其设置为true即可。

文档指出: A Boolean value that indicates whether the physics body’s node is pinned to its parent node. The default value is false. If true, the node’s position is fixed relative to its parent. The node’s position cannot be changed by actions or physics forces. The node can freely rotate around its position in response to collisions or other forces. If the parent node has a physics body, the two physics bodies are treated as if they are connected with a pin joint.

相关内容

最新更新