FloatObject.re.js 782 B

1234567891011121314151617181920212223242526
  1. import * as RE from 'rogue-engine'
  2. import * as THREE from 'three'
  3. export default class FloatObject extends RE.Component {
  4. elapsed = 0
  5. @RE.Prop("Vector3") amplitude = new THREE.Vector3(0, 1, 0)
  6. @RE.Prop("Vector3") offset = new THREE.Vector3(0, 0, 0)
  7. @RE.Prop("Vector3") period = new THREE.Vector3(0, 4, 0)
  8. awake() {
  9. }
  10. start() {
  11. this.elapsed = 0
  12. }
  13. update() {
  14. this.elapsed += RE.Runtime.deltaTime
  15. this.object3d.position.x = this.amplitude.x * Math.cos(this.period.x * this.elapsed) + this.offset.x
  16. this.object3d.position.y = this.amplitude.y * Math.sin(this.period.y * this.elapsed) + this.offset.y
  17. this.object3d.position.z = this.amplitude.z * Math.sin(this.period.z * this.elapsed) + this.offset.z
  18. }
  19. }
  20. RE.registerComponent(FloatObject);