In this little quick tip video, I will show you how to create an idle hover behavior for objects in Creative Experience. When you play your experience the object will move slightly in your scene. You'll need to use the small script below.
Let's have a look:
Here is the script you have to use:
beScript.onStart = function () { this.destRandom = 0; this.srcRandom = 0; this.positionOffset = new DSMath.Vector3D(); this.startPosition = this.actor.getPosition(); }; beScript.onStop = function () { //Will be called on experience stop. }; beScript.execute = function (context) { beScript.hover(context.elapsedTime); }; beScript.hover = function (currentTime) { currentTime *= this.Speed / 100; if (Math.abs(this.destRandom - this.srcRandom) < 0.01) { this.srcRandom = this.destRandom; this.destRandom = Math.random() - 0.5; } this.srcRandom = this.srcRandom * 0.98 + this.destRandom * 0.02; this.positionOffset.x = Math.sin(currentTime * this.Frequency * 0.0004) * this.Amplitude * 10 * this.srcRandom + Math.cos(currentTime * this.Frequency * 0.001) * this.Amplitude * 3.5 * this.srcRandom; this.positionOffset.z = Math.cos(currentTime * this.Frequency * 0.00055) * this.Amplitude * 10 * this.srcRandom + Math.cos(currentTime * this.Frequency * 0.0012) * this.Amplitude * 2 * this.srcRandom; this.positionOffset.y = Math.cos(currentTime * this.Frequency * 0.00046) * this.Amplitude * 8 * this.srcRandom + Math.sin(currentTime * this.Frequency * 0.001) * this.Amplitude * 3 * this.srcRandom; this.actor.setPosition(this.positionOffset.add(this.startPosition)); };