Skip to content

Instantly share code, notes, and snippets.

@xexu
Last active May 9, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xexu/4666394e9b356efa05d86581c4b87b94 to your computer and use it in GitHub Desktop.
Save xexu/4666394e9b356efa05d86581c4b87b94 to your computer and use it in GitHub Desktop.
A-Frame custom component
<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