我正在尝试加入一个带炮塔的坦克,但由于这个联合,整个模型都在晃动,你知道导致这种行为的原因吗?
项目链接:Project
这就是我的做法:
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];
Best Answer-推荐答案 strong>
我认为有两个问题:
- 您正在分配一个节点与其子节点之一(炮塔和坦克)之间的约束。这不太可能给出预期的结果,因为子节点的位置是相对于其父节点的(假设约束移动父节点,它也会移动子节点)。
- 您正在两个静态物体(枪和炮塔)之间分配约束 - 这应该没有效果
关于ios - 场景套件中的铰链接头发生奇怪的晃动,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/24718770/
|