2014-10-22 47 views
4

是否可以使用applyAngularImpulse而不是按指數方式增加輪子的速度?
理想情況下,我想讓車輪跟隨我的手指,但設置node.zRotation += atan2f(y2-y1, x2-x1)讓我的車輪失去控制。這是我看中了,但感覺很靠不住的:在SpriteKit中使用touchesMoved旋轉獎金輪

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 
    SKNode *node = [self nodeAtPoint:location]; 

    CGPoint positionInScene = [touch locationInNode:self]; 
    CGPoint previousPosition = [touch previousLocationInNode:self]; 

    [node.physicsBody applyAngularImpulse:(previousPosition.x - positionInScene.x) * 0.1]; 
    node.physicsBody.angularDamping = 1; 
} 

場景:https://dl.dropboxusercontent.com/s/gexfburjm1coude/Screen%20Shot%202014-10-21%20at%2010.30.31%20PM.png?dl=0

回答

2

將您的衝動後:

[node.physicsBody applyAngularImpulse:theImpulse]; 

角速度簡單地鉗位到最大速度,其價值取決於你想讓輪子旋轉多快:

const CGFloat maxAngularVelocity = 2.5; 
node.physicsBody.angularVelocity = MIN(node.physicsBody.angularVelocity, maxAngularVelocity);