Search code examples
iosswiftsprite-kitskphysicsjoint

SKPhysicsJointSpring frequency & damping in Swift


What is the difference between damping and frequency properties of a SKPhysicsJointSpring ?

the code I have is

var spring = SKPhysicsJointSpring.jointWithBodyA(
            body1.physicsBody,
            bodyB: body2.physicsBody,
            anchorA: body1.position,
            anchorB: body2.position)
spring.frequency = 1.8
spring.damping = 0.5
self.physicsWorld.addJoint(spring1)

body1.physicsBody?.dynamic = false
body2.physicsBody?.dynamic = true

In what range of values should frequency and damping fall so that the spring acts naturally?


Solution

  • Answer depends on what you consider "natural".

    Damping means that the spring will dissipate energy with each oscillation and eventually come to rest.

    Zero damping means that the mass attached to the spring will oscillate forever.

    Such a system usually has three constants associated with it:

    1. mass m (lbm)
    2. spring stiffness k (lbf/in)
    3. damping coefficient c

    It's well known that frequency f^2 = k/m.

    When that system talks about spring "frequency" it makes no sense to me.