RoboMan.js 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //rotate current node around Y axis
  21. node.yaw(180);
  22. };
  23. self.update = function(timeStep) {
  24. //rotate current node around Y axis
  25. node.yaw(180);
  26. if (idle != controller.idle) {
  27. idle = controller.idle;
  28. if (idle)
  29. animCtrl.playExclusive("Idle", 0, true, 0.1);
  30. else
  31. animCtrl.playExclusive("Run", 0, true, 0.1);
  32. }
  33. };
  34. };