User Manual

Scripting

Scripts are how you make your PlayCanvas application interactive. They are written in regular JavaScript the same programming language that is used to program web pages.

You can think of your application as divided into two separate code bases. The Engine, which is provided by PlayCanvas, implements general purpose functionality such as graphics rendering, input handling, audio, and the interface to the PlayCanvas tools; and Scripts which are often specific to your application or re-usable chunks that provide useful behaviours.

Generally you won't have to worry about the engine code, it's a single JavaScript file included into your application. If you're rewriting parts of the engine you probably don't need this introduction to scripting.

Here is an example of a simple script. It is called "rotate" and it rotates the entity that it is attached to by 10° every second.

var Rotate = pc.createScript("rotate");

Rotate.prototype.update = function (dt) {
    this.entity.rotate(0, 10*dt, 0);
};

Scripts are defined by the name given when they are created and they are attached to Script Component via the Editor or by adding a script component to an Entity in your code.

Terminology

Lets define a few pieces of terminology.