Contents

SpatialTemplateElementDirection

The initial direction a participant faces when an activity starts.

Declaration

struct SpatialTemplateElementDirection

Overview

A SpatialTemplateElementDirection type indicates where a participant faces at the start of an activity. You might configure participants to face your app’s content, another participant, or an arbitrary point in the shared coordinate system. You can also modify an existing direction value by adding an arbitrary amount of additional rotation. When a participant joins an activity, the system sets the initial orientation of their spatial Persona to the direction assigned to their seat position. If you don’t specify an initial direction for a seat, the participant faces your app’s content.

The following example creates a spatial template for a table tennis game with four participants and a spectator. The template places the red and blue teams at opposite ends of the table along the z-axis, and each person faces the app’s content along that axis. The final participant sits to the side of the table to watch the game.

struct TableTennis: SpatialTemplate {
    enum Role: String, SpatialTemplateRole {
        case blueTeam
        case redTeam
    }

    var elements: [any SpatialTemplateElement] = [
        .seat(position: .app.offsetBy(x: -1, z: -3), direction: .alignedWith(appAxis: .z), role: Role.blueTeam),
        .seat(position: .app.offsetBy(x: -1, z:  3), direction: .alignedWith(appAxis: .z), role: Role.redTeam),

        .seat(position: .app.offsetBy(x:  1, z: -3), direction: .alignedWith(appAxis: .z), role: Role.blueTeam),
        .seat(position: .app.offsetBy(x:  1, z:  3), direction: .alignedWith(appAxis: .z), role: Role.redTeam),

        .seat(position: .app.offsetBy(x: -2, z:  0))
    ]
}

Topics

Looking at a specific location

Looking along an axis

Rotating the element

Operators

See Also

Custom spatial templates