Incorrect behaviour with SKPhysicsJointPin when shouldEnableLimits is true and lowerAngleLimit and upperAngleLimit set

前端 未结 2 1413
暖寄归人
暖寄归人 2021-01-05 10:30

I currently have a ragdoll figure, which consists of a parent node (with no physics bodies attached), and lots of child nodes which each consist of a circle body. The circle

2条回答
  •  我在风中等你
    2021-01-05 11:21

    "I currently use a value of -0.05 and 0.05 for lowerAngleLimit and upperAngleLimit respectively"

    According to the docs...

    upperAngleLimit - The largest angle allowed for the pin joint, in radians.

    ...the limits are in radians.

    0.05 radians = 2.86478898 degrees
    

    So, you are only allowing the bodies to move about 5 degrees total. This is an extremely small range. From my experience, SpriteKit starts this weird snapping behavior when the body is forced out of range.

    I don't think this behavior is specific to upside down bodies. My best guess is that the physics engine doesn't have the frame rate to apply the force of gravity in one frame and catch the body before its moved out of range in the next.

    You should increase the range. I prefer to specify it in degrees. For example...

    func degreesToRadians(degrees: CGFloat) -> CGFloat {
        return CGFloat(M_PI) * degrees / 180.0
    }
    
    pinJoint.shouldEnableLimits = true
    pinJoint.lowerAngleLimit = degreesToRadians(-30.0)
    pinJoint.upperAngleLimit = degreesToRadians(180.0)
    

    You'll have to tinker with the angles, mass and gravity until you find a sweet spot where things move realistically.

    If you really want a range of motion that small, I'd consider just disabling it altogether.

    circle.physicsBody?.allowsRotation = false
    

提交回复
热议问题