OrbitEntityAction
An action which animates the transform of an entity to revolve around a specified pivot entity.
Declaration
struct OrbitEntityActionOverview
This action moves an entity in a circular path by gradually adjusting its local transform. The animation starts from the entity’s initial transform, and rotates around the pivot entity. The orbitalAxis specifies which cartesian axis to rotate around in world space.. The axis is resolved when the action starts to produce an axis of rotation around the pivot entity. The full orbit completes after the action has ended.
The example below creates an animation that orbits an entity around the x-axis two times for five seconds.
// Create an action entity resolution to the pivot entity
// that exists in the scene.
let pivotEntity: ActionEntityResolution = .entityNamed("pivotEntity")
// Create an action that performs an orbit around the
// specified pivot entity.
let orbitEntityAction = OrbitEntityAction(pivotEntity: pivotEntity,
revolutions: 2,
orbitalAxis: [0, 1, 0],
isOrientedToPath: true,
isAdditive: false)
// A five second animation that plays an animation causing the entity to
// orbit around the pivot.
let orbitAnimation = try AnimationResource
.makeActionAnimation(for: orbitEntityAction,
duration: 5.0,
bindTarget: .transform)
// Play the five second orbit animation.
entity.playAnimation(orbitAnimation)