Skip to main content

Scripting

Scripts are the heart of interactivity in PlayCanvas. They're reusable pieces of code that you attach to Entities to define behaviors, handle user input, manage game logic, and bring your projects to life.

Two Scripting Systems

PlayCanvas supports two scripting approaches:

  • ESM Scripts (.mjs files) - Modern ES Module-based scripts using class syntax. Recommended for new projects.
  • Classic Scripts (.js files) - The original PlayCanvas scripting system using prototype-based syntax.

Both systems can coexist in the same project, allowing you to migrate gradually or use whichever approach fits your needs.

Quick Example

Here's a simple script that rotates an entity:

import { Script } from 'playcanvas';

export class Rotate extends Script {
static scriptName = 'rotate';

/** @attribute */
speed = 10;

update(dt) {
this.entity.rotate(0, this.speed * dt, 0);
}
}

What You'll Learn

Fundamentals

Core concepts that apply to all PlayCanvas scripts:

Editor Integration

Working with scripts in the PlayCanvas Editor:

Debugging

Tools and techniques for troubleshooting your scripts:

tip

New to PlayCanvas scripting? Start with Getting Started to learn the basics, then explore ESM Scripts for the modern approach.