我正在尝试制作一条左右移动的多个身体部位的蛇。我正在使用别针,但在蛇停止时,身体一直在移动并且不会停止。我已经弄乱了最大和最小角度以及扭矩,但似乎没有任何效果。我应该使用不同类型的关节吗?
答案 0 :(得分:0)
很抱歉,我无法登录我的其他帐户,但是这是代码。基本上第二部分只是摇摆不定。我希望增加7-8个部件,但他们只是继续摇摆,特别是在移动后#34;头部"。我想要一个流畅的"猛扑"我移动蛇的动作。
self.physicsWorld.gravity = CGVectorMake(0, -100)
self.physicsWorld.contactDelegate = self
head.size = CGSize(width: 25,height: 25)
head.physicsBody = SKPhysicsBody(texture: head.texture, size: head.size)
head.position = CGPointMake(100,400)
head.anchorPoint = CGPoint(x: 0.5, y: 1)
head.physicsBody!.dynamic = false
head.zPosition = 3
self.addChild(head)
var p1 = SKSpriteNode(imageNamed: "snakeBodyPart.png")
p1.size = CGSize(width: 25,height: 25)
p1.physicsBody = SKPhysicsBody(texture: p1.texture, size: p1.size)
p1.position = CGPointMake(100,380)
p1.anchorPoint = CGPoint(x: 0.5, y: 1)
p1.physicsBody!.dynamic = true
addChild(p1)
var joint = SKPhysicsJointPin.jointWithBodyA(head.physicsBody, bodyB: p1.physicsBody, anchor: CGPoint(x: CGRectGetMidX(head.frame), y: CGRectGetMinY(head.frame) + 10))
joint.upperAngleLimit = 0.1
joint.rotationSpeed = 0.1
self.physicsWorld.addJoint(joint)