Keep and Share logo     Log In  |  Mobile View  |  Help  
 
Visiting
 
Select a Color
   
 
pulse (1).txt
var Pulse = pc.createScript('pulse');

Pulse.attributes.add("pulseTimeSecs", {type: "number", default: 2, title: "Pulse Time Secs"});

// initialize code called once per entity
Pulse.prototype.initialize = function() {
   this.secsSinceStart = this.pulseTimeSecs + 1;
   this.entity.on("pulse:start", this.onStartEvent, this);
};

// update code called every frame
Pulse.prototype.update = function(dt) {
   this.secsSinceStart += dt;
   
   if (this.secsSinceStart <= this.pulseTimeSecs) {
       var normalisedTime = this.secsSinceStart / this.pulseTimeSecs;
       var pingPongTime = Math.abs(normalisedTime -0.5) * 2;
       var scale = (0.3 * pingPongTime) + 0.7;
       var localScale = this.entity.getLocalScale();
       localScale.set(scale, scale, scale);
       this.entity.setLocalScale(localScale);
   }
};

Pulse.prototype.onStartEvent = function() {
   this.secsSinceStart = 0;
};

Creation date: Jan 28, 2022 11:08am     Last modified date: Jan 28, 2022 11:09am   Last visit date: Dec 7, 2024 9:27am
    Report Objectionable Content