SCNNode static body with .dae causing issues

限于喜欢 提交于 2019-12-24 05:15:10

问题


I have built a landscape model in blender, exported to .dae and added to my xcode project.

I have loaded the scene then attached the child (landscape grid mesh) to my landscapeNode, this loads perfectly.

However when I attach a static physics body to the landscspeNode my heroNode seems to crash into a invisible wall when attempting to fly above the land.

The functionality I am looking for is the obvious collision with the land I have modelled so the heroNode cannot fly through the land and is forced to move around it.

Note: I did not do any converting of the y axis in blender nor xcode just simply rotated the node 90degrees about the -x axis.

Edit: code i've attempted to add physics shape

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}]];

回答1:


If you don't specify additional options when creating a physics body for a node, what you get is a convex hull encompassing that node's geometry.

Because your landscape is a static body, you can make it use a concave shape that more closely approximates the geometry. (Note that this works only for static bodies.) To do this, you'll need to:

  1. Use the bodyWithShape:type: method to create the body, not staticBody.
  2. For that method you need to pass an SCNPhysicsShape. Create one with shapeWithGeometry:options: or shapeWithNode:options:.
  3. For the options parameter, pass a dictionary containing the key SCNPhysicsShapeTypeKey and corresponding value SCNPhysicsShapeTypeConcavePolyhedron.


来源:https://stackoverflow.com/questions/27503183/scnnode-static-body-with-dae-causing-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!