gpt4 book ai didi

swift 2 : Stop movement after applyImpulse

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:31 26 4
gpt4 key购买 nike

我怎样才能在 Sprite 被施加这样的冲动后停止它:

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

是否有可能使运动在一段时间内减少? (2 秒)

最佳答案

为了停止 physicsBody 的运动,您可以像这样使用“速度”变量:

//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”和影响 angularVelocity(旋转)的“angularDamping”。这些 physicsBody 参数允许您在施加脉冲(类似于摩擦)后随时间减慢速度。

//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

关于 swift 2 : Stop movement after applyImpulse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com