How Do I Move a Player And Camera

Hey Everyone. I was wondering what do i type in the script to move a player and the camera with the arrow keys. i am new at this and really want to make my first game. Thanks For the help!!

You can assign this script to any entity to move it around:

    var Movement = pc.createScript('movement');

    Movement.attributes.add('speed', { type: 'number', default: 1 });

    // initialize code called once per entity
    Movement.prototype.initialize = function() {

    // update code called every frame
    Movement.prototype.update = function(dt) {
        var left =;
        var right =;
        var up =;
        var down =;

        if (left) {
            this.entity.translate(-this.speed * dt, 0, 0);
        if (right) {
            this.entity.translate(this.speed * dt, 0, 0);
        if (up) {
            this.entity.translate(0, 0, -this.speed * dt);
        if (down) {
            this.entity.translate(0, 0, this.speed * dt);

    // swap method called for script hot-reloading
    // inherit your script state here
    Movement.prototype.swap = function(old) {


    // to learn more about script anatomy, please read:

Don’t forget to parse the script to show the ‘speed’ script attribute in the Editor UI.

Do you also have a gravity script???

If you want gravity applied to objects in your scene, you might want to take a look at the PlayCanvas physics engine.

Here is some introductory information:

And a simple tutorial:

Instead of moving a physics object around with the translate function, you’d use forces/impulses instead.

If you use the script that @will gave you, then you can put it on the player and make the camera a child. That’s what I did here.

1 Like

is thia js cuz thats what it works in making a game