<commit_before>pc.script.attribute('shakeMagnifier','number',2);
pc.script.attribute('shakeDamping','number',12);
pc.script.attribute('shakeSpringConstant','number',700);
pc.script.attribute('followtargetname','string','Avatar');
pc.script.attribute('followdistance','number',15);


pc.script.create('shakeycamera', function (context) {
    // Creates a new Shakeycamera instance
    var Shakeycamera = function (entity) {
        this.entity = entity;
        this.shakevalue = 0.0;
        this.shakevelocity = 0.0;
        
        this.baserotation = pc.math.quat.create();
        pc.math.quat.copy(this.entity.getLocalRotation(), this.baserotation);
        this.shakerotation = pc.math.quat.create();
        this.modifiedrotation = pc.math.quat.create();
        
        this.baseposition = pc.math.vec3.create();
        pc.math.vec3.copy(this.entity.getLocalPosition(), this.baseposition);
        this.shakeposition = pc.math.vec3.create();
        
        this.modifiedposition = pc.math.vec3.create();

        this.shakeaxis = pc.math.vec3.create(1,0,0);

        this.followoffset = pc.math.vec3.create(0,this.followdistance, this.followdistance);
    };

    Shakeycamera.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
            this.followtarget = this.entity.getRoot().findByName(this.followtargetname);
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
            // if following a target, update the position
            if (this.followtarget) {
                pc.math.vec3.add(this.followtarget.getLocalPosition(), this.followoffset, this.baseposition);
            }

            var shakedamping = (1.0 - dt * this.shakeDamping);
            if (shakedamping < 0) { shakedamping = 0; }
            
            this.shakevelocity = this.shakevelocity  * shakedamping - this.shakevalue * this.shakeSpringConstant * dt;
            this.shakevalue = this.shakevalue + dt * this.shakevelocity;
            
            //pc.math.quat.fromAxisAngle(this.shakeaxis, this.shakevalue * this.shakeMagnifier, this.shakerotation);
            pc.math.quat.fromEulerXYZ(0,0,this.shakevalue * this.shakeMagnifier,this.shakerotation);
            pc.math.quat.multiply(this.baserotation, this.shakerotation, this.modifiedrotation);
            
            this.entity.setLocalRotation(this.modifiedrotation);
            
            pc.math.vec3.set(0, this.shakeposition, this.shakevalue * this.shakeMagnifier, 0);
            pc.math.vec3.add(this.baseposition, this.shakeposition, this.modifiedposition);
            
            this.entity.setLocalPosition(this.modifiedposition);
        },
        
        addShake: function(shakeamplitude) {
            console.log("shake", shakeamplitude);
            this.shakevalue = this.shakevalue + shakeamplitude;
        }
    };

    return Shakeycamera;
});<commit_msg>Whoops, followoffset isn't valid until initialize()<commit_after>pc.script.attribute('shakeMagnifier','number',2);
pc.script.attribute('shakeDamping','number',12);
pc.script.attribute('shakeSpringConstant','number',700);
pc.script.attribute('followtargetname','string','Avatar');
pc.script.attribute('followdistance','number',15);


pc.script.create('shakeycamera', function (context) {
    // Creates a new Shakeycamera instance
    var Shakeycamera = function (entity) {
        this.entity = entity;
        this.shakevalue = 0.0;
        this.shakevelocity = 0.0;
        
        this.baserotation = pc.math.quat.create();
        pc.math.quat.copy(this.entity.getLocalRotation(), this.baserotation);
        this.shakerotation = pc.math.quat.create();
        this.modifiedrotation = pc.math.quat.create();
        
        this.baseposition = pc.math.vec3.create();
        pc.math.vec3.copy(this.entity.getLocalPosition(), this.baseposition);
        this.shakeposition = pc.math.vec3.create();
        
        this.modifiedposition = pc.math.vec3.create();

        this.shakeaxis = pc.math.vec3.create(1,0,0);
    };

    Shakeycamera.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
            this.followtarget = this.entity.getRoot().findByName(this.followtargetname);
            this.followoffset = pc.math.vec3.create(0,this.followdistance, this.followdistance);
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
            // if following a target, update the position
            if (this.followtarget) {
                pc.math.vec3.add(this.followtarget.getLocalPosition(), this.followoffset, this.baseposition);
            }

            var shakedamping = (1.0 - dt * this.shakeDamping);
            if (shakedamping < 0) { shakedamping = 0; }
            
            this.shakevelocity = this.shakevelocity  * shakedamping - this.shakevalue * this.shakeSpringConstant * dt;
            this.shakevalue = this.shakevalue + dt * this.shakevelocity;
            
            //pc.math.quat.fromAxisAngle(this.shakeaxis, this.shakevalue * this.shakeMagnifier, this.shakerotation);
            pc.math.quat.fromEulerXYZ(0,0,this.shakevalue * this.shakeMagnifier,this.shakerotation);
            pc.math.quat.multiply(this.baserotation, this.shakerotation, this.modifiedrotation);
            
            this.entity.setLocalRotation(this.modifiedrotation);
            
            pc.math.vec3.set(0, this.shakeposition, this.shakevalue * this.shakeMagnifier, 0);
            pc.math.vec3.add(this.baseposition, this.shakeposition, this.modifiedposition);
            
            this.entity.setLocalPosition(this.modifiedposition);
        },
        
        addShake: function(shakeamplitude) {
            console.log("shake", shakeamplitude);
            this.shakevalue = this.shakevalue + shakeamplitude;
        }
    };

    return Shakeycamera;
});
{'fraction_non_alphanumeric': 0.1219471673035388, 'fraction_numerical': 0.010965276624023924, 'mean_word_length': 2.5349383440986495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7100819', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1710, 'n_words': 275}