Create Your First Horizon World
By following this tutorial, you’ll learn how to create a simple Horizon Worlds game. In the process, you’ll explore the basic workflow involved in:
- Setting up your Horizon tooling
- Creating a new Horizon World
- Adding entities to it
- Scripting entity behavior
The game is simple: you shoot at a target, and you get a point each time you hit it.
Section 1: Set Up Your Workstation
To develop in Horizon Worlds, you’ll need the following:
- A Windows PC or VR headset
- Meta Quest application (Oculus client app) for Windows: Update via the Repair option if necessary
- Meta Horizon Worlds application from the Meta Quest Store
- Visual Studio Code
Section 2: Create a New World
-
Launch the Meta Quest Application:
- Start Meta Horizon Worlds in Desktop Mode.
- Navigate to the Meta Horizon Worlds app in the Library.
- Click the app’s menu icon (…) and select Start in Desktop Mode.
-
Create a New World:
- Click New World and name it (e.g., “Super Cool World”).
- Select Custom Model Import and click Create.
Section 3: Import Game Assets
-
Open the Assets Panel:
- Click the Assets tab at the bottom of the screen.
-
Add New Assets:
- Click Add New > 3D Model.
- Enable Preserve Offset Pivots in the Import Models dialog.
- Select your asset files (e.g., StoneFloor.fbx and StoneFloor_BR.png) and click Import.
-
Position Assets:
- Drag the StoneFloor asset into the scene.
- Use the position manipulator handles (press “W”) to align the asset.
- Duplicate and align multiple floor tiles for a larger area.
Section 4: Add a Pedestal and Rifle
-
Import and Position Pedestal:
- Import SingleBlock.fbx and StoneBlockKit_BR.png.
- Place and rename the object “Pedestal”.
-
Import and Position Rifle:
- Import ACWpnBattleRifle.fbx and its texture files.
- Place the rifle on the pedestal.
- Rename the object “Rifle”.
Section 5: Make the Rifle Grabbable
- Select the Rifle:
- In the Property panel, set Motion to “Interactive” and Interaction to “Grabbable”.
Section 6: Test Your World
-
Enable Auto-Start Simulation:
- Open the Preview Configuration panel and enable both Auto-start simulation on Preview entry and Auto-start simulation on Preview exit.
-
Preview Mode:
- Click the person icon to enter Preview Mode.
- Pick up the rifle and ensure it behaves as expected.
Section 7: Add a Simple Script
-
Create a Script:
- Open the Scripts Panel and click the plus button.
- Name the script “Shoot” and open it in Visual Studio Code.
2. Add Debug Code:
-
Replace the
start()
function with:start() {
console.log("Hello, World!");
} -
Save the script and attach it to the Rifle object.
Test the Script:
- Enter Preview Mode. The Console should display “Hello, World!” when the Rifle is created.
Section 8: Trigger a Rifle Event
Update the Script:
-
Replace the
start()
function with:start() {
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnIndexTriggerDown, (player: hz.Player) => {
console.log("boom!");
});
}
Test the Script:
- Save and test by firing the rifle in Preview Mode.
- Each shot should log “boom!” to the Console.
Next Steps
You’ve successfully built a basic interactive world! Continue exploring by refining your scripts, adding new assets, or experimenting with advanced scripting techniques.