Lukas
Lukas

Reputation: 491

remove bouncing from PhysicsBody?

How can I completely remove the bounciness from my PhysicsBodies, I already set the restitution of all PhysicsBodies to 0 but when multiple PhysicsBodies collide they still bounce off of each other, how can turn this off? Here's a video where i swipe up and down which triggers this code on the blue SpriteNodes:

node.physicsBody?.applyImpulse(CGVector(dx: x, dy: y))

https://i.sstatic.net/wugbK.jpg

I want the blue SpriteNodes to just stay up or down and not bounce away

Upvotes: 2

Views: 290

Answers (1)

Confused
Confused

Reputation: 6278

Are you experimenting in a space without any world damping/friction? If so, you will need to zero the velocity of objects the moment they collide in order to get zero bounce. But you'll also need to move them outside the boundary of the objects they collided with.

By way of explanation: This is, I presume, happening because your objects are achieving a (slight) state of overlap right before the collision is reported to the physics engine. When this happens, the first response of some physics engines is to remove this overlap by moving the object with a corrective amount of force or movement. What's happening looks like a continuation of that movement.

In some physics engines you get the opportunity to determine how strongly the corrective behaviour is, and how frequently it occurs, and even set the physics simulation to much higher rates of solving than the frame rate. In these engines you could find the right balance of settings to prevent this. But not in SpriteKit.

Upvotes: 0

Related Questions