Swift 2:applyImpulse后停止移动

3

当一个精灵被施加了如下的冲量,我该如何停止它:

player.physicsBody!.applyImpulse(CGVectorMake(50, 0))

移动是否可以在一段时间内(2秒)逐渐减少?

1个回答

7
为了停止物理体的运动,您可以像这样利用“速度”变量:
//this will reset the x, y based velocity to a halt/stop    
player.physicsBody?.velocity = CGVectorMake(0, 0)
//if you would also like to stop any rotation that may be present
player.physicsBody?.angularVelocity = 0

回答你的第二个问题,你应该研究一下'linearDamping'来影响速度和'angularDamping'来影响角速度(旋转)。这些物理体参数允许你在施加冲量后随着时间的推移减慢速度(类似于摩擦力)。
//These values should be set when creating the physicsBody.
//should experiment with these values to get the desired effect.
player.physicsBody?.linearDamping = 1.10
player.physicsBody?.angularDamping = 0.25

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接