swiftskspritenodemomentum

Stop an SKPhysicsBody mid-motion


If an SKSpriteNode has had an impulse applied to its SKPhysicsBody so that it now has momentum, is there a way I can get it to immediately stop moving? Applying an equal and opposite impulse would probably work in theory, but I would like to know if there is a simpler way. Thanks (:


Solution

  • You can set its velocity to zero:

    body.velocity = CGVectorMake(0, 0)
    

    You might also want to set its angular velocity to zero:

    body.angularVelocity = 0
    

    And if you want it to become immune to forces and impulses, turn off dynamic:

    body.dynamic = false