问题
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:
- Use the bodyWithShape:type: method to create the body, not
staticBody
. - For that method you need to pass an SCNPhysicsShape. Create one with
shapeWithGeometry:options:
orshapeWithNode:options:
. - For the options parameter, pass a dictionary containing the key
SCNPhysicsShapeTypeKey
and corresponding valueSCNPhysicsShapeTypeConcavePolyhedron
.
来源:https://stackoverflow.com/questions/27503183/scnnode-static-body-with-dae-causing-issues