1
\$\begingroup\$

I'm trying to move an object over a period of ten seconds from y coordinate 0 to y coordinate 10. the object is created at y coordinate 0. The problem is when the animation starts, the object pops to the end position for like one second or so then pops back down to the starting position and begins the animation properly. Why is the object ending moving to the end location instantly, and how can I prevent this from happening?

//create box bottom
func createGrabBox() {
    grabbottom = grabBox.rootNode.childNodeWithName("grabbottom", recursively: true)!
    grabbottom.position.y = 0
    grabbottom.geometry!.firstMaterial!.transparency = 0.5
    grabbottom.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: nil)
    grabbottom.physicsBody!.restitution = 0.0
    grabbottom.physicsBody!.friction = 1.0
    grabbottom.physicsBody!.categoryBitMask = ColliderType.grabBottomCatagory.rawValue
    grabbottom.physicsBody!.collisionBitMask = ColliderType.diceCatagory.rawValue
    scene.rootNode.addChildNode(grabbottom)

    //animation snippet
    SCNTransaction.begin()
    SCNTransaction.setAnimationDuration(10.0)
    SCNTransaction.setCompletionBlock() { }
    grabbottom.position.y = 10
    SCNTransaction.commit()

    //physics field for this object
    let field = SCNPhysicsField.linearGravityField()
    field.strength = 0
    field.direction = SCNVector3(x: 0, y: 0, z: 0)
    field.categoryBitMask = ColliderType.grabBottomCatagory.rawValue
    //only things with categories that match the field's will be affected by it
    let fieldNode = SCNNode()
    fieldNode.physicsField = field
    scene.rootNode.addChildNode(fieldNode)
}
\$\endgroup\$
1
\$\begingroup\$

I found that it is because I was using a dynamic body rather than a kinematic body. I still have a bit of learning in regards to how physics works with scene kit.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.