Cover for the App

Studio: Roaming Entities

Studio

This project showcases how to make roaming entities in Niantic Studio.

This project showcases how to make roaming entities in Niantic Studio.

Roaming Entity Sample Project

This project showcases how to make roaming 3D entities (in this case, UFOs) using Niantic Studio. You’ll learn how to:

  • Assign a custom component to 3D models in your scene.
  • Move and animate entities between random positions using a simple state machine.
  • Detect collisions and trigger particle effects for visual feedback.

Project Structure

├── assets/

│ └── ufo.glb // 3D model of the UFO

├── roaming_entity.ts // Main script defining the roaming_entity component

├── cleanup.ts // Utility for cleaning up event listeners

└── README.md // This README file

Key Files

    • Defines a component with a state machine (/) for moving the UFO to random positions.
    • Sets up colliders, positions, and collision listeners that trigger particle effects.
    • Provides helper functions (, ) to remove events and references when a component is removed.

How It Works

  1. Roaming Entity Component

    • Registered in . The UFO is placed initially at , then assigned a Cylinder collider.
    • A collision listener triggers , spawning a brief particle burst.
  2. State Machine

    • PING → PONG cycle:
      • On entering each state, the UFO transitions to a new random position via .
      • A random delay determines how long before it switches states again, creating continuous roaming.
  3. Collision Handling

    • is used. When the UFO collides, particles are emitted.
    • After a short duration, the particle emitter and a rotation animation are removed, resetting the UFO for its next collision.
  4. Cleanup

    • Event listeners for the collision are tracked and later removed to prevent memory leaks, using and .

Getting Started

  1. Clone This Project

    • Clone this sample project into your workspace from this page.
  2. Assign the Component

    • If you add or change models/entities from the ufos, ensure you attach the 'roaming_entity.ts' custom component to each.
  3. Verify or trade out the assets

    • If youi use your own model, but make sure to replace the 'assets/ufo.glb' reference in the 'roaming+entity.ts' component file
  4. Build & Preview

    • Press Build to run or publish the project.
    • Watch your objects roam around the scene, occasionally colliding and spawning particle effects.

Customization

  • Motion Settings

    • Edit to fine-tune random distances or set new min/max positions.
    • Adjust in for faster or slower travel.
  • Particle Effects

    • In , tweak properties such as , , , and to change the burst’s look.
  • Collision Shape and size

    • Swap out the Cylinder collider for or another shape if you prefer. Change the size to give your objects more space from other objects before colliding.
  • Animation Easing

    • Experiment with different values (, , , etc.) to personalize the objects movement style.

Troubleshooting

  • No Movement

    • Ensure the component is attached to each UFO in the Inspector.
    • Confirm the state machine transitions () are being triggered (check console logs).
  • No Random Motion

    • Check that the function is returning valid numbers.
    • Adjust the random range or the minimum positions so they remain in camera view.

Enjoy experimenting with roaming UFOs, collisions, and creative effects in Niantic Studio!