gpt4 book ai didi

ios - 相邻的 SKPhysicsBody 无法正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:34 24 4
gpt4 key购买 nike

我在尝试将两个具有物理实体的 block 放在彼此之上时遇到问题。

http://s1173.photobucket.com/user/Kyle_Decot/media/example_zps02f027fe.mp4.html

正如您在视频中看到的那样,我能够将我的积木放在堆叠的积木之上,即使它们是彼此叠放的。

玩家方 block 和其他方 block 都继承自 Block 基类,如下所示

#import "Block.h"

@implementation Block

+ (void)loadSharedAssets {

}

- (id)initWithColor:(UIColor *)color size:(CGSize)size {

self = [super initWithColor:color size:size];

if (self) {

self.texture = [SKTexture textureWithImageNamed:@"tile"];

self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize: self.size];
self.physicsBody.usesPreciseCollisionDetection = YES;
self.physicsBody.dynamic = NO;


}

return self;
}

@end

更新

我添加了一张图片使问题更清楚一点。本质上的问题是,即使蓝色方 block 彼此正上方,我仍然能够跳起来(使用红色方 block )并坐在底部蓝色方 block 的边缘(这不应该是可能的)。物理物体或其他东西似乎有些不对劲。

enter image description here

您可以看到,由于某种原因,红色方 block 高于相邻的蓝色方 block ,并且“位于”底部蓝色方 block 的边缘。当我跳起来反对它时。

最佳答案

编辑:用答案替换原来的建议

滚动到 box2d documentation4.5 边缘形状 部分|你会找到原因(SpriteKit 在引擎盖下使用 Box2D 来实现它的物理)

In many cases a game environment is constructed by connect several edge shapes end-to-end. This can give rise to an unexpected artifact when a polygon slides along the chain of edges. In the figure below we see a box colliding with an internal vertex. These ghost collisions are caused when the polygon collides with an internal vertex generating an internal collision normal.

此处的两条边(edge1 和 edge2)是您游戏中两个蓝色框的左侧边(想象一下它逆时针旋转了 90 度)

Box2D 引入了 ChainShapes 来解决这个问题(您可以在 5.6 Edge Shapes 部分找到引用。

这个想法是在同时生成多个盒子时用这些顶点链替换正方形物理体组。

我相信您可以使用 bodyWithEdgeChainFromPath 在 SpriteKit 中访问这些内容并传入由要组合以形成碰撞链的框的角点组成的 Core Graphics 路径

关于ios - 相邻的 SKPhysicsBody 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21734959/

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