ShipMoveReceiver.re.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as RE from 'rogue-engine';
  2. import { Vector2 } from 'three';
  3. import RaycastReceiver from '../RaycastReceiver.re';
  4. export default class ShipMoveReceiver extends RaycastReceiver {
  5. @RE.Prop("Object3D") ship
  6. awake() {
  7. }
  8. start() {
  9. // this.ship = RE.getComponentByName("Player", this.parent)
  10. // //let ship = RE.Runtime.scene.getObjectByName("Ship")
  11. // if(this.ship == null) {
  12. // RE.Debug.logError("Did not find ship")
  13. // return
  14. // }
  15. this.player = RE.getComponentByName("Player", this.ship)
  16. this.targetAngle = this.player.angle
  17. }
  18. update() {
  19. this.object3d.rotation.z = - this.player.angle + (Math.PI / 2)
  20. }
  21. onMouseOver(intersect) {
  22. if(RE.Input.mouse.getButtonPressed(2)) {
  23. return
  24. }
  25. this.targetAngle = this.angleTo(intersect.uv, new Vector2(0.5, 0.5))
  26. this.player.targetAngle = this.targetAngle
  27. if (RE.Input.touch.touches.length == 1) {
  28. this.player.thrust()
  29. }
  30. }
  31. onMouseOut(){
  32. }
  33. angleTo(source, destination) {
  34. return Math.atan2(source.y - destination.y, source.x - destination.x)
  35. }
  36. }
  37. RE.registerComponent(ShipMoveReceiver);