Last active
May 9, 2018 10:28
-
-
Save xexu/4666394e9b356efa05d86581c4b87b94 to your computer and use it in GitHub Desktop.
A-Frame custom component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var direction = 1; | |
AFRAME.registerComponent('auto-camera', { | |
tick: function () { | |
var currentPosition = this.el.object3D.position; | |
if (currentPosition.z < -2) { | |
direction = 1; | |
} else if (currentPosition.z > 0) { | |
direction = -1; | |
} | |
var delta = 0.05; | |
this.el.setAttribute('position', { | |
x: currentPosition.x, | |
y: currentPosition.y, | |
z: currentPosition.z + delta * direction | |
}); | |
} | |
}); | |
</script> | |
<a-entity position="0 1.6 0" auto-camera> | |
<a-camera></a-camera> | |
</a-entity> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment