gpt4 book ai didi

ios - SpriteKit - 为什么我的弹跳球会穿过地面?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:22 25 4
gpt4 key购买 nike

我正在使用 SpriteKit 物理引擎开发一个小型弹跳球游戏。我的问题是:

当我对弹跳球施加巨大的冲力使其快速落地时,有时它可能会穿过地面(非常薄,高度=2)。

我在 Apple 文档中找到了这个,但它不起作用。

Specify High Precision Collisions for Small or Fast-Moving Objects When Sprite Kit performs collision detection, it first determines the locations of all of the physics bodies in the scene. Then it determines whether collisions or contacts occurred. This computational method is fast, but can sometimes result in missed collisions. A small body might move so fast that it completely passes through another physics body without ever having a frame of animation where the two touch each other.

If you have physics bodies that must collide, you can hint to Sprite Kit to use a more precise collision model to check for interactions. This model is more expensive, so it should be used sparingly. When either body uses precise collisions, multiple movement positions are contacted and tested to ensure that all contacts are detected.

ship.physicsBody.usesPreciseCollisionDetection = YES;

最佳答案

您可以设置 Sprite 的 node.physicsBody.usesPreciseCollisionDetection = YES; 但这并不能保证碰撞标志一直存在,因为 Sprite 的速度可能太高了。

您应该对您的节点应用速度限制,以防止它们运行得太快。像这样:

if(node.physicsBody.velocity.dx > 200)
node.physicsBody.velocity = CGVectorMake(200, node.physicsBody.velocity.dy);

上面的代码示例会将节点的右移动 dx 限制为 200,同时保持 dy(上/下)速度不变。

关于ios - SpriteKit - 为什么我的弹跳球会穿过地面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29872718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com