Skip to content

Commit

Permalink
Move and rotate flashlight a bit randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
vilcans committed Nov 28, 2013
1 parent a71c879 commit 869db3e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/FlashlightComponent.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
define([
'goo/entities/components/Component',
'goo/entities/components/LightComponent',
'goo/entities/components/ScriptComponent',
'goo/renderer/light/SpotLight',
'goo/noise/ValueNoise',
'lib/Game'
], function(
Component,
LightComponent,
ScriptComponent,
SpotLight,
ValueNoise,
Game
) {
'use strict';
Expand All @@ -20,6 +24,22 @@ define([

var spotLightEntity = Game.goo.world.createEntity('FlashLight');
spotLightEntity.setComponent(new LightComponent(spotLight));
var script = new ScriptComponent();
var time = 0;
script.run = function(entity, tpf, environment) {
time += tpf;
var rotY = (ValueNoise.evaluate1d(time, 1.1) - .5) * .15;
var rotX = (ValueNoise.evaluate1d(time, 1.3) - .5) * .13;
var posX = (ValueNoise.evaluate1d(time + 11919, 1.3) - .5) * .2;
var posY = (ValueNoise.evaluate1d(time + 31900, 1.3) - .5) * .2;
spotLightEntity.transformComponent.transform.translation.setd(posX, posY, 0);
spotLightEntity.transformComponent.setRotation(rotX, rotY, 0);
spotLightEntity.transformComponent.setUpdated();

spotLight.intensity = (ValueNoise.evaluate1d(time, 2.3) - .5) * .2;;
}
spotLightEntity.setComponent(script);

spotLightEntity.addToWorld();

Game.viewCam.transformComponent.attachChild( spotLightEntity.transformComponent);
Expand Down

0 comments on commit 869db3e

Please sign in to comment.