Tim Andrews
Tim Andrews

Reputation: 847

How can I make SCNNode position animation move at a uniform rate?

I have a game that I am animating in swift using scenekit and the provided animation framework, core animation.

The problem I am having is that my animation is not smooth. Moving a node from point A to point B results in a small ramp up in move speed and a small ramp down when it gets close to the desired position. I wish for the speed to remain uniform throughout. This is a problem because my animations don't move very far and they happen frequently (2 per second + computational delay) resulting in it looking very jerky.

So my question is, is there any way to make the animation speed uniform?

Edit: Just for clarity I am using SCNTransaction. My code looks something like this: Half pseudocode

func simulate(){
    SCNTransaction.begin()
     SCNTransaction.setAnimationDuration(0.5)
    SCNTransaction.setCompletionBlock{
        //If no victory this simulate func is run again
        checkVictory()
    }

    for all gameObjects{
    object.position = calculateNewPos()
 }
 SCNTransaction.commit()

}

Upvotes: 3

Views: 1495

Answers (1)

mnuages
mnuages

Reputation: 13462

the default timing function is kCAMediaTimingFunctionDefault.

Setting SCNTransaction's animationTimingFunction to [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear] might solve your issue.

Upvotes: 3

Related Questions