RoboMan.js 836 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // designate component
  2. "atomic component";
  3. exports.component = function(self) {
  4. var node = self.node;
  5. var animCtrl = node.getComponent("AnimationController");
  6. var controller = node.getJSComponent("AvatarController");
  7. var idle = true;
  8. self.start = function() {
  9. var camera = node.scene.getMainCamera();
  10. if (camera) {
  11. camera.node.position = [0, 0, -10];
  12. camera.node.pitch(20);
  13. }
  14. animCtrl.playExclusive("Idle", 0, true, 0.0);
  15. node.yaw(180);
  16. }
  17. // we need an update or it doesn't run the start, fix in JSVM
  18. self.update = function(timeStep) {
  19. node.yaw(180);
  20. if (idle != controller.idle) {
  21. idle = controller.idle;
  22. if (idle)
  23. animCtrl.playExclusive("Idle", 0, true, 0.1);
  24. else
  25. animCtrl.playExclusive("Run", 0, true, 0.1);
  26. }
  27. }
  28. }