Search code examples
iosobjective-csprite-kit

Sprite Kit Restitution?


I was just curious as to what exactly Sprite Kit Restitution actually configures? I know that it configures some behavior about an SKPhysicsBody's parameters, but how does the behavior differ?


Solution

  • In iOS Games by Tutorials, a SpriteKit SKPhysicsBody's restitution is defined as follows:

    "a property describing how much energy a body retains when it bounces off of another body, basically a fancy way of saying "bounciness""

    See also this excerpt from the iOS Developer Library (Apple Docs)

    This property is used to determine how much energy the physics body loses when it bounces off another object. The property must be a value between 0.0 and 1.0. The default value is 0.2.

    Also just note that the compiler won't complain if you supply values outside of the range from (0.0 to 1.0); however, think about what it will mean to have a value greater than 1, for example. The body would actually end a collision with MORE energy than it had initially. That's not very realistic behavior and oftentimes will very quickly break your physics simulation.