我正在尝试加入一个带炮塔的坦克,但由于这个联合,整个模型都在摇晃,你知道是什么导致了这种行为吗?
项目链接:项目
这就是我做到的:
SCNNode *tankNode = [extraScene.rootNode childNodeWithName:@"Main_Body" recursively:YES];
[tankNode setScale:SCNVector3Make(0.003, 0.003, 0.003)];
[tankNode setPosition:SCNVector3Make(0, 1, 0)];
[tankNode setPhysicsBody:[SCNPhysicsBody dynamicBody]];
[tankNode setRotation:SCNVector4Make(0, 1, 0, -M_PI_2)];
[scene.rootNode addChildNode:tankNode];
SCNNode *turretNode = [tankNode childNodeWithName:@"Turret" recursively:YES];
turretNode.physicsBody = [SCNPhysicsBody staticBody];
SCNNode *gunNode = [turretNode childNodeWithName:@"gun" recursively:YES];
gunNode.physicsBody = [SCNPhysicsBody staticBody];
SCNPhysicsHingeJoint *gunJoint = [SCNPhysicsHingeJoint jointWithBodyA:turretNode.physicsBody axisA:SCNVector3Make(0,0,1) anchorA:SCNVector3Make(0.1,0.1,0.1) bodyB:gunNode.physicsBody axisB:SCNVector3Make(0,0,1) anchorB:SCNVector3Make(0.1,0.1,0.1)];
[scene.physicsWorld addBehavior:gunJoint];
SCNPhysicsHingeJoint *turretJoint = [SCNPhysicsHingeJoint jointWithBodyA:turretNode.physicsBody axisA:SCNVector3Make(0,1,0) anchorA:SCNVector3Make(0.1,0.1,0.1) bodyB:tankNode.physicsBody axisB:SCNVector3Make(0,1,0) anchorB:SCNVector3Make(0.5,0.5,-0.1)];
[scene.physicsWorld addBehavior:turretJoint];