我在 Blender 中构建了一个景观模型,导出到 .dae 并添加到我的 xcode 项目中。
我已经加载了场景,然后将子项(景观网格)附加到我的景观节点,这加载完美。
然而,当我将静态物理体附加到 landscspeNode 时,我的 HeroNode 在尝试飞越陆地时似乎撞上了无形的墙壁。
我正在寻找的功能是与我建模的土地发生明显的碰撞,因此 HeroNode 无法飞过土地并被迫在其周围移动。
注意:我没有在 Blender 中对 y 轴进行任何转换,xcode 也只是简单地将节点绕 -x 轴旋转 90 度。
编辑:我尝试添加物理形状的代码
landscapeNode.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeStatic shape:[SCNPhysicsShape shapeWithNode: [landscapeScene.rootNode childNodeWithName:@"Grid" recursively:NO] options:@{SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConcavePolyhedron}]];
landscapeNode.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeStatic shape:[SCNPhysicsShape shapeWithNode: landscapeNode options:@{SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConcavePolyhedron}]];
landscapeNode.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeStatic shape:[SCNPhysicsShape shapeWithGeometry: landscapeNode.geometry options:@{SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConcavePolyhedron}]];
如果在为节点创建物理体时没有指定附加选项,那么您得到的是凸包 https://en.wikipedia.org/wiki/Convex_hull包含该节点的几何形状。
由于您的景观是静态物体,因此您可以使其使用更接近几何形状的凹面形状。 (请注意,这仅适用于静态物体。)为此,您需要:
- Use the bodyWithShape:type: https://developer.apple.com/library/mac/documentation/SceneKit/Reference/SCNPhysicsBody_Class/index.html#//apple_ref/occ/clm/SCNPhysicsBody/bodyWithType:shape:创建身体的方法,而不是
staticBody
.
- 对于该方法,您需要传递一个SCNPhysicsShape https://developer.apple.com/library/mac/documentation/SceneKit/Reference/SCNPhysicsShape_Class/index.html。创建一个与
shapeWithGeometry:options:
or shapeWithNode:options:
.
- For the options参数,传递一个包含key的字典
SCNPhysicsShapeTypeKey
以及对应的值SCNPhysicsShapeTypeConcavePolyhedron
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)