How do I adjust the orbit distance (radius) of OrbitAnimation?

23 Views Asked by At

Right now I have

let animationDefinition = OrbitAnimation(
  duration: 5, axis: [0, 1, 0], startTransform: transform,
  orientToPath: false, bindTarget: .transform, repeatMode: AnimationRepeatMode.repeat)

I want the adjust the radius of the orbit. Changing axis: [0, 100, 0] does not as expected.

I noticed in the docs they pass rotation and translation but they don't document what they do and when I try to use them, I get

Extra arguments at positions #4, #5 in call

I'm guessing rotation and translation control the radius but I'm not sure how they work.

1

There are 1 best solutions below

0
wonton On

Radius is controlled by the translation component of Transform. translation is not passed to OrbitAnimation but rather to a Transform object passed as startTransform.

So instead of using model.transform, pass in a Transform and set translation to the radius you want.

The parenthesis in the docs can be confusing. With this spacing it becomes obvious:

let animationDefinition = OrbitAnimation(
    duration: 5, axis: [0, 1, 0],
    startTransform: Transform(
      scale: simd_float3(10,10,10),
      rotation: simd_quatf(ix: 1, iy: 90, iz: 1, r: 100),
      translation: simd_float3(101, 1, 3)
    ),
    orientToPath: false, bindTarget: .transform,
    repeatMode: AnimationRepeatMode.repeat)