Acoop
Acoop

Reputation: 2666

Completely stop sprite on collision

I am building a game where the player sprite bounces around the GameScene. When the user taps the screen, the player sprite should stick to the next wall it hits. How can I completely remove all the energy from the sprite so that it no longer moves?

What attributes should I change? I have tried setting:

restitution() = 0

but this does not help.

I am looking for an answer for SpriteKit in Swift.

Thanks for any help.

Upvotes: 1

Views: 66

Answers (1)

sangony
sangony

Reputation: 11696

You are talking about a node's velocity. It's dx and dy values to be exact.

yourNode.physicsBody?.velocity = CGVectorMake( 0, 0 )

the above will set your node's x and y axis velocity to zero.

Upvotes: 1

Related Questions