PlayerPawnInput.re.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as RE from 'rogue-engine';
  2. import RapierMovementController from './RapierMovementController.re';
  3. export default class PlayerPawnInput extends RE.Component {
  4. movementController:RapierMovementController
  5. @RE.props.checkbox() useStrafe: boolean = false
  6. awake() {
  7. }
  8. start() {
  9. this.object3d.traverse(obj => {
  10. const components = RE.getObjectComponents(obj);
  11. components.forEach(comp => {
  12. if (comp instanceof RapierMovementController) {
  13. this.movementController = comp
  14. }
  15. });
  16. });
  17. this.object3d.traverse(obj => {
  18. const components = RE.getObjectComponents(obj);
  19. components.forEach(comp => {
  20. });
  21. });
  22. }
  23. update() {
  24. if (RE.Input.keyboard.getKeyPressed("KeyW")) {
  25. this.movementController.thrust = true
  26. }
  27. if (RE.Input.keyboard.getKeyPressed("KeyA")) {
  28. if(this.useStrafe) {
  29. this.movementController.strafeLeft = true
  30. } else {
  31. this.movementController.rotateLeft = true
  32. }
  33. }
  34. if (RE.Input.keyboard.getKeyPressed("KeyS")) {
  35. this.movementController.brake = true
  36. }
  37. if (RE.Input.keyboard.getKeyPressed("KeyD")) {
  38. if(this.useStrafe) {
  39. this.movementController.strafeRight = true
  40. } else {
  41. this.movementController.rotateRight = true
  42. }
  43. }
  44. if (RE.Input.keyboard.getKeyPressed("Space")) {
  45. this.movementController.jump = true
  46. }
  47. if (RE.Input.keyboard.getKeyUp("Space")) {
  48. this.movementController.jump = false
  49. this.movementController.hasJumped = false
  50. }
  51. }
  52. }
  53. RE.registerComponent(PlayerPawnInput);