How to make a script to follow camera?

Hello,

I am making a script for follow camera for the player but it is my first time doing something like this. Would I do this.eulers?
Here is the script I made so far.


FollowCam.attributes.add('FollowEntity', {type: 'entity', description: 'Entity to Follow'});

// initialize code called once per entity
FollowCam.prototype.initialize = function() {
    
    this.pos = new pc.Vec3();
    
    this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
    this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);

    
};

// update code called every frame
FollowCam.prototype.update = function(dt) {
       if(this.app.keyboard.isPressed(pc.KEY_A)) {
           pc.KEY_A = true; 
           pc.KEY_B = false; 
           pc.KEY_C = false; 
           pc.KEY_D = false; 
           pc.KEY_E = false; 
           pc.KEY_F = false;
           pc.KEY_G = false;
           pc.KEY_H = false;
           pc.KEY_I = false; 
           pc.KEY_J = false; 
           pc.KEY_L = false; 
           pc.KEY_M = false; 
           pc.KEY_N = false; 
           pc.KEY_O = false; 
           pc.KEY_P = false; 
           pc.KEY_Q = false; 
           pc.KEY_R = false; 
           pc.KEY_S = false; 
           pc.KEY_T = false; 
           pc.KEY_U = false; 
           pc.KEY_V = false; 
           pc.KEY_W = false; 
           pc.KEY_X = false; 
           pc.KEY_Y = false; 
           pc.KEY_Z = false; 
           
    } 
};

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

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/```

Maybe something like this?

       if (this.eulers.x < 0) this.eulers.x += 360;
        if (this.eulers.y < 0) this.eulers.y += 360;

Hi @Gabriel_Dobrzynski, if you still have your first project(the ball rolling game), then that has a pretty easy to understand camera follow script, Iā€™d suggest studying that to begin with.

1 Like

I do because it still is a work in progress.

1 Like