MovementController.re.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import GetForwardVector from 'Assets/Library/GetForwardVector';
  2. import * as RE from 'rogue-engine';
  3. import * as THREE from 'three'
  4. export default class MovementController extends RE.Component {
  5. @RE.props.num() speed: number = 1
  6. vectorCalculator: GetForwardVector
  7. awake() {
  8. }
  9. start() {
  10. this.vectorCalculator = new GetForwardVector(RE.Runtime.camera)
  11. }
  12. update() {
  13. if (RE.Input.keyboard.getKeyPressed("KeyW")) {
  14. this.moveForward(1 * this.speed)
  15. }
  16. if (RE.Input.keyboard.getKeyPressed("KeyA")) {
  17. this.moveRight(-1* this.speed)
  18. }
  19. if (RE.Input.keyboard.getKeyPressed("KeyS")) {
  20. this.moveForward(-1* this.speed)
  21. }
  22. if (RE.Input.keyboard.getKeyPressed("KeyD")) {
  23. this.moveRight(1* this.speed)
  24. }
  25. }
  26. moveForward(distance) {
  27. this.object3d.position.addScaledVector(this.vectorCalculator.getForward(), distance);
  28. }
  29. moveRight(distance) {
  30. this.object3d.position.addScaledVector(this.vectorCalculator.getRight(), distance);
  31. }
  32. }
  33. RE.registerComponent(MovementController);