RoboMan.js 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // designate component
  2. "atomic component";
  3. //A RoboMan component
  4. exports.component = function(self) {
  5. //link to the current node
  6. var node = self.node;
  7. //get Animation and Avatar controller components
  8. var animCtrl = node.getComponent("AnimationController");
  9. var controller = node.getJSComponent("AvatarController");
  10. var idle = true;
  11. self.start = function() {
  12. //get main camera of the current scene
  13. var camera = node.scene.getMainCamera();
  14. //if it exist
  15. if (camera) {
  16. camera.node.position = [0, 0, -10];
  17. camera.node.pitch(20);
  18. }
  19. animCtrl.playExclusive("Idle", 0, true, 0.0);
  20. };
  21. self.update = function(timeStep) {
  22. if (idle != controller.idle) {
  23. idle = controller.idle;
  24. if (idle)
  25. animCtrl.playExclusive("Idle", 0, true, 0.1);
  26. else
  27. animCtrl.playExclusive("Run", 0, true, 0.1);
  28. }
  29. };
  30. };